2
我已經在Angular2中定義了一個指令,並且我希望將它提供給我的所有組件,而不必在每個組件中執行:directives: [MyDir]
。Angular2:在整個應用程序中提供指令
我想應該有一個辦法,因爲*ngIf
實例隨處可用。
我已經在Angular2中定義了一個指令,並且我希望將它提供給我的所有組件,而不必在每個組件中執行:directives: [MyDir]
。Angular2:在整個應用程序中提供指令
我想應該有一個辦法,因爲*ngIf
實例隨處可用。
更新
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})
]);
謝謝主席先生,正是我需要的。我也發現這一點:http://blog.thoughtram.io/angular2/2015/11/23/multi-providers-in-angular-2.html這可能是有用的。 – Scipion