我想使用此功能来创建全局管道: https://angular.io/docs/ts/latest/api/core/index/PLATFORM_PIPES-let.html
但这已被弃用,它说: 不推荐通过提供商提供平台管道。通过 AppModule 提供平台管道。
文档确实不存在,这是我需要将旧版本制作成新版本的:
import {PLATFORM_PIPES} from '@angular/core';
import {OtherPipe} from './myPipe';
@Component({
selector: 'my-component',
template: `
{{123 | other-pipe}}
`
})
export class MyComponent {
...
}
bootstrap(MyComponent, [{provide: PLATFORM_PIPES, useValue: [OtherPipe], multi:true}]);
那么有谁知道如何将此示例转换为使用 AppModule 的新版本?
最佳答案
AppModules 是相当新的,并且最近发生了很大的变化(可能会出现在 RC.5 中)。我现在会坚持使用已弃用的方法。
我还没有测试过它,但类似这样的东西应该可以满足你的要求:
@AppModule({
// modules: [MyModule],
providers: [...]
pipes: [OtherPipe]
})
class MyModule {}
bootstrap(AppCmp, {modules: [RouterModule, MyModule])
关于typescript - 没有 PLATFORM_PIPES 的 Angular 2 全局管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38484113/