【问题标题】:Get reference to injector inside Angular 2.X custom module?在 Angular 2.X 自定义模块中获取对注入器的引用?
【发布时间】:2018-03-13 15:27:40
【问题描述】:

我们如何在应用模块中获得对依赖注入器的引用?

这是自定义模块的示例代码。那么我们如何在这个类中获得对 Angular DI(依赖注入器)的引用呢?

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

  }

}

【问题讨论】:

    标签: angular angular5 angular2-di angular2-injection


    【解决方案1】:

    你是说这个?

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

    【讨论】:

    • (顺便说一下来自@angular/core
    • 这正是我想要的:)!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    相关资源
    最近更新 更多