【问题标题】:Angular2: Make a directive available in the whole app [duplicate]Angular2:在整个应用程序中提供指令[重复]
【发布时间】:2016-10-07 08:18:33
【问题描述】:

我在 Angular2 中定义了一个指令,我想让它对我的所有组件都可用,而不必这样做:directives: [MyDir] 在每个组件中。

我想应该有一种方法,因为 *ngIf 按实例在任何地方都可用。

【问题讨论】:

    标签: angular


    【解决方案1】:

    更新

    PLATFORM_DIRECTIVES 在 2.0.0 决赛中消失了。 见How to make directives and components available globally

    原创

    bootstrap()提供

    bootstrap(AppComponent, [
      // for global directives
      provide(PLATFORM_DIRECTIVES, {useValue: [MyDir], multi: true}),
      // for global pipes
      provide(PLATFORM_PIPES, {useValue: [RainbowizePipe], multi:true})
    ]);
    

    【讨论】:

    猜你喜欢
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2017-03-01
    相关资源
    最近更新 更多