Scipion Scipion - 3 months ago 60
TypeScript Question

Angular2 PLATFORM_DIRECTIVES in rc.5

I have just migrated from rc.4 to rc.5. However, my custom directives that I did define for the whole app aren't recognized anymore.

I used to have in my app.component :

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


Now with the NgModule I do have :

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


CustomDirective1 and CustomDirective2 are not recognized anymore though in my app. Is there anything else I should be doing ?

Answer

Directives should go in a module's declarations:

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