I have a feature module named MyModule
which provides a service named ModalsService
, I want to inject this ModalsService
into another service named ApiService
which belongs to my main application and is marked as being provided in the root
@Injectable()
export class ModalsService { ... }
@NgModule({
providers: [
BetterModalsService
]
})
export class MyModule { }
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(
private modalsService: ModalsService
) { }
...
}
Everything compiles without error but upon trying to call the ModalsService
service from the ApiService
I get an error that this.modalsService
is undefined. I am also injecting the ModalsService
service into some components from the main app which works as expected. This leads me to believe that there is some dependency injection trickery going on that I do not understand.
I've tried to use providers: [ApiService]
in my app.module.ts
rather than providedIn: 'root'
but this makes no difference. Any help would be appreciated.