typescript - 没有 PLATFORM_PIPES 的 Angular 2 全局管道

标签 typescript angular

我想使用此功能来创建全局管道: 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/

相关文章:

javascript - 在 Angular 中禁用 ngFor 中的一个按钮

javascript - 在 Draft JS 中实现自动完成但没有像 "trigger"这样的 "@"

angular - FormBuilder 给出控制台错误

Angular/Typescript 以编程方式将图像(blob)复制到剪贴板

angular - 如何使 PDF 适合高度 - ng2-pdf-viewer

angular - 忽略 ng build --prod 中的 `assets` 文件夹

visual-studio - ts 属性推送在 Angular 代码 VS 中的类型 '{}' 上不存在

typescript - 我可以在 typescript 项目中使用 CommonJS 模块系统吗?

javascript - typescript 代码 : How to calculate Totale=Sum(Subtotale) and price* quantita = subtotale Angular5

javascript - 使用 Typescript 1.5 时 Angular 为 null 并且需要