How to use legacy providers and directives in the new bootstrapModule module introduced in angular rc. 5

I used to have a bootstrap call in main.ts, for example:

bootstrap(AppComponent, [
    APP_ROUTER_PROVIDERS,
    HTTP_PROVIDERS,
    disableDeprecatedForms(),
    provideForms(),
    {
        provide: PLATFORM_DIRECTIVES, multi: true, useValue: MATERIAL_DIRECTIVES
    }
])

In short, Angular rc.4 -> rc.5 migration guide offers a new way to download the application, i.e. bootstrapModulewhich initializes the root module:

platformBrowserDynamic().bootstrapModule(
    AppModule
)

Question: How to pass obsolete / user directives and providers when used bootstrapModuleinstead of an older call bootstrap?

My guess: These providers and directives should be included somewhere within app.module.ts, but how exactly will we wrap these directives and providers using the module, is it not clear to me?

@NgModule({
    declarations: [AppComponent],

    imports: [
        BrowserModule,
        FormsModule,
        RouterModule,
    ],

    bootstrap: [AppComponent],
})
export class AppModule {}
+4
1

https://angular.io/docs/ts/latest/guide/ngmodule.html

, http://angular.io https://github.com/angular/angular.io/blob/master/public/docs/ts/latest/guide/ngmodule.jade https://github.com/angular/angular.io/tree/master/public/docs/_examples/ngmodule/ts

AppModule https://github.com/angular/angular.io/blob/master/public/docs/_examples/ngmodule/ts/app/app.module.1.ts

@NgModule({
  imports: [ BrowserModule, FormsModule ],
  declarations: [
    AppComponent,
    HighlightDirective,
    TitleComponent,

    AwesomePipe,
    ContactComponent,
    ContactHighlightDirective
  ],
  providers: [ UserService ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule);
+4

Source: https://habr.com/ru/post/1650774/


All Articles