angularangular5angular2-diangular2-injection

Get reference to injector inside Angular 2.X custom module?


How we can get a reference to dependency injector inside the application module ?

Here is the example code of the custom module. So how we can get reference to Angular DI (Dependency Injector) inside this class ?

@NgModule({
  declarations: [
    MyApplication,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [MyApplication]
})
export class MyApplicationModule {
  constructor() {

  }

}

Solution

  • You mean this ?

    export class MyApplicationModule {
      constructor(private injector: Injector) {}
    }