angular - 如何在 angular rc.5 中引入的新 bootstrapModule 中使用旧版提供程序和指令

标签 angular

早些时候,我在 main.ts 中有一个 Bootstrap 调用,例如:

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

简而言之,Angular rc.4 -> rc.5 migration guide提出了一种引导应用程序的新方法,即初始化根模块的 bootstrapModule:

platformBrowserDynamic().bootstrapModule(
    AppModule
)

问题: 在使用 bootstrapModule 而不是旧的 bootstrap 调用时,我们如何传递遗留/自定义指令和提供程序?

我的猜测是: 这些提供程序和指令应该包含在 app.module.ts 中的某处,但我不清楚我们如何使用模块包装这些指令和提供程序?

@NgModule({
    declarations: [AppComponent],

    imports: [
        BrowserModule,
        FormsModule,
        RouterModule,
    ],

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

最佳答案

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);

关于angular - 如何在 angular rc.5 中引入的新 bootstrapModule 中使用旧版提供程序和指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38867497/

相关文章:

Angular CanDeactivate Guard : How to wait for the right or the next value of an Obersavble?

angular - 如何读取 firebase 推送通知内容并触发 ionic2 中的方法?

angular - 将数据从一个组件传递到angular4中的另一个组件

Angular - 如何在 Angular 9 - Ivy 中进行代码拆分?

typescript - RxJs BehaviorSubject 的订阅者未收到值更改通知的问题

java - 无法下载文件 : cannot be resolved to URL because it does not exist with Spring

angular - 在 Angular 中使用 ngIf 出错

javascript - 如何在 Angular 6 中实现 bootstrap scrollspy?

angular - 获取错误对象(...)的 Ionic App Availability 插件不是函数

javascript - 当我更改页面时,地理位置给我一个错误