The service providers are constructor functions. When instantiated they must contain a property called $get, which holds the service factory function.
Questions tagged [angular-providers]
173 questions
5
votes
1 answer
No Provider for router in Angular 2
As a newbie, I am having issues setting up routes in Angular 2.
Though I am pretty sure, it is something very basic I am missing.
All I want is my App Component to load up and show me the title. And just below it, a link that would load up the…

StrugglingCoder
- 4,781
- 16
- 69
- 103
4
votes
2 answers
angular useFactory return async Function in module
I am trying to figure out how to use useFactory as an async function in Angular 11. Right now I have this:
import { ApolloClientOptions } from 'apollo-client';
import { FirebaseService } from './firebase.service';
// other imports here...
export…

Jonathan
- 3,893
- 5
- 46
- 77
4
votes
1 answer
How to update a value provided by a provider in Angular?
I have a provider in AppModule which provides a class.
Is there a way to update the provided value at runtime?
{provide: MatDatepickerIntl, useClass: SomeClass}
How can replace SomeClass with AnotherClass at runtime (i.e.: when reacting to an event…

user2297996
- 1,382
- 3
- 18
- 28
4
votes
3 answers
NullInjectorError: StaticInjectorError on NgxSpinnerService; NullInjectorError: No provider for t! while trying hosting in firebase
I am trying to host my app in firebase everything works fine in localhost but when I successfully host app in firebase at firebase domain, it shows:
NullInjectorError: StaticInjectorError(wo)[class{constructor(t,e) at SpinnerService at content is…

Roshan Aale
- 51
- 1
- 4
4
votes
0 answers
Is there a way to enforce typesafety for Angular providers with dependency injection?
I would like to use dependency injection to swap the implementation of the provider but can't figure out how to make that type safe.
@Injectable()
class ExampleService {
exampleMethod(): string {
return 'test';
}
}
// Note that…

bogeylicious
- 5,071
- 3
- 25
- 17
4
votes
0 answers
Load all parent routes dynamically in angular when app is bootstraped or loaded
I am using angular 2 to build an application where I need to check the base href and match it with my predefined sets of parent routes in my app.routes.ts file.
Currently I have created a hard-coded array of parentRoutes = ['login', 'signup',…

Antara Datta
- 1,909
- 2
- 12
- 16
4
votes
1 answer
How to mock config-phase providers for unit tests?
I'm writing a spec that checks a method is called during the config phase of the Angular module under test.
Here's a simplified look at the code being tested:
angular.module('core',['services.configAction'])
.config(function(configAction){
…

Francisc
- 77,430
- 63
- 180
- 276
3
votes
1 answer
Angular dependency injection: providers vs imports
the Angular documentation on dependency injection has confused me.
I understand that Angular DI works by specifying to the DI (the injector) something to "provide" via the providers array on the metadata object passed to NgModule (for the whole…

user603563
- 374
- 3
- 15
3
votes
1 answer
Does Angular component from lazy loaded module gets copy of the global service?
Angular docs I'm not sure if I understand
Angular providers documentation states:
When the Angular router lazy-loads a module, it creates a new
injector. This injector is a child of the root application injector.
Imagine a tree of injectors;…

Robert Kusznier
- 6,471
- 9
- 50
- 71
3
votes
1 answer
No provider for simple component
Makes no sense it was working until 5 mins ago ...
this is the component
import { Component, OnInit } from '@angular/core';
import {Osobaa} from '../osobaa';
import { Osoba } from '../osoba';
import {OsobaService} from…

Алекса Јевтић
- 497
- 3
- 7
- 17
3
votes
4 answers
how to prevent duplicated $http requests in AngularJS app?
I need to prevent sending the same request repeatedly to API before the previous request will give the response. I have found out some solutions. But, I don't want to disable the button while waiting for response because I have more API calls in my…

user3391137
- 431
- 8
- 26
2
votes
0 answers
Tree-shaking in Angular Lazy Modules
I can't really get why are services, that are marked with providedIn:root and that are used only in lazy-loaded modules aren't tree shaked. We don't have our lazy modules in initial bundle but have services that are used in them, why? And how does…

Iceneo
- 51
- 3
2
votes
1 answer
Angular standalone component's providers not working or not applied
I have a standalone component and I'd like to open a modal from in it (which is another standalone component but it is not matter now I guess).
I want to apply global rules for the material dialog, so I provide it in my component's provider. But it…

Procisz
- 21
- 5
2
votes
1 answer
Provide an InjectionToken after APP_INITIALIZATION with the resolved configuration
I need to get the config using a factory that will be resolved during the APP INITIALIZATION (using the APP_INITIALIZER provider).
export function loadConfig(): () => Promise {
// return promised config
}
That is provided using the…

frankfullstack
- 498
- 5
- 18
2
votes
1 answer
Angular providers: Provide value dynamically based on @Input() parameter
export const FormatDate = new InjectionToken('FormatDate');
...
@Component({
selector: '...',
templateUrl: '...',
styleUrls: ['...'],
providers: [{ provide: FormatDate, useValue: 'MM.yyyy' }]
})
export class DatePicker {
@Input() format:…

Anton Fil
- 223
- 2
- 8