I have just started reading some code from somewhere else and I have to understand it. I have read a lot in Angular website and some other coding related websites but I have not undersoot the following section yet and need your help.
export class AppComponent {
w: FooService;
constructor(private injector: Injector) {
if (environment.production) {
this.w = this.injector.get(FooService);
}
}
}
I do not understand why the developer has injected the FooService in such a way, and why didn't he implemented the injection like bellow:
export class AppComponent {
constructor(w: FooService) {
}
}
And finally, would you please explain the main goal of this.injector.get()?