全域性可用的定製管道
要使應用程式範圍內的自定義管道可用,請在應用程式引導期間擴充套件 PLATFORM_PIPES。
import { bootstrap } from '@angular/platform-browser-dynamic';
import { provide, PLATFORM_PIPES } from '@angular/core';
import { AppComponent } from './app.component';
import { MyPipe } from './my.pipe'; // your custom pipe
bootstrap(AppComponent, [
provide(PLATFORM_PIPES, {
useValue: [
MyPipe
],
multi: true
})
]);
教程: https : //scotch.io/tutorials/create-a-globally-available-custom-pipe-in-angular-2