Angular2:全局添加多个指令

时间:2016-08-10 18:17:12

标签: angular angular-material

我想将@ angular2-material指令添加到“global”指令中。为此,我目前有以下引导功能:

bootstrap(AppComponent, [
    disableDeprecatedForms(),
    provideForms(),
    provideRouter(routes),
    provide(PLATFORM_DIRECTIVES, { useValue: MdToolbar, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdButton, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdInput, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdCheckbox, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdRadioButton, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdRadioGroup, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MdIcon, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MD_SIDENAV_DIRECTIVES, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MD_LIST_DIRECTIVES, multi: true }),
    provide(PLATFORM_DIRECTIVES, { useValue: MD_CARD_DIRECTIVES, multi: true })
]);

有没有办法在1 go中执行此操作,而不是在多个“重复”行中单独添加它们?

1 个答案:

答案 0 :(得分:0)

<强>更新

自2.0.0 final以来,不再支持全局添加指令。

另见Declaring multiple components in @ngModule Angular 2

<强>原始

bootstrap(AppComponent, [
    disableDeprecatedForms(),
    provideForms(),
    provideRouter(routes),
    provide(PLATFORM_DIRECTIVES, { useValue: [
      MdToolbar,
      MdButton,
      MdInput,
      MdCheckbox,
      MdRadioButton,
      MdRadioGroup,
      MdIcon,
      MD_SIDENAV_DIRECTIVES,
      MD_LIST_DIRECTIVES,
      MD_CARD_DIRECTIVES], 
    multi: true })
]);

使用新推出的模块,可以在RC.5中轻松完成。只需从模块中导出它们即可导入模块。 https://angular.io/docs/ts/latest/guide/ngmodule.html