When we create a Service, Angluar CLI will helps us to add: @#Injectable({ providedIn: 'root' }) It only create a instance in root dependency tree. If there is no reference to use this provider, Angular will remove it from our production code. But th…
In this lesson, we discuss how and when to use factory providers, to enable dependencies that shouldn’t be available to Angular’s DI. If you have this service: export class LoggerProvider { constructor(enabled: boolean){ if(enabled){ console.log("Log…
This lesson discusses when and how to add dependencies, resolved by Angular’s DI, to factory providers. The example used in this lesson builts upon the previous lesson on understanding factory providers. For example, the LoggerProvider need to use Co…
Unlike 'useClass', 'useExisting' doesn't create a new instance when you register your service inside ngmodule. 'useExisting' also can limit the function call, for example: import { Injectable, Inject } from '@angular/core'; import { Http } from '@ang…