Angular2 PLATFORM_DIRECTIVES在rc.5中

时间:2016-08-25 07:31:19

标签: angular typescript

我刚从rc.4迁移到rc.5。但是,我为整个应用程序定义的自定义指令不再被识别。

我曾经在我的app.component:

bootstrap(AppComponent, [
 provide(PLATFORM_DIRECTIVES, {useValue: [CustomDirective1, CustomDirective2], multi: true})
])

现在有了NgModule,我确实有:

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule
    ],
    providers: [
      provide(PLATFORM_DIRECTIVES, {useValue: [CustomDirective1, CustomDirective2], multi: true})
    ],
    bootstrap:    [AppComponent],
})

虽然在我的应用程序中不再识别CustomDirective1和CustomDirective2。还有什么我应该做的吗?

1 个答案:

答案 0 :(得分:4)

Directives should go in a module's declarations

@NgModule({
    declarations: [
        AppComponent,
        CustomDirective1,
        CustomDirective2
    ],
    imports: [
        BrowserModule
    ],
    providers: [],
    bootstrap: [AppComponent],
})