Angular使用自定义管道
发布时间:2020-12-17 17:59:07 所属栏目:安全 来源:网络整理
导读:我很乐意帮助将内置管道导入角度为2的自定义管道. 这是我的代码: @Pipe({ name: 'tablePipe' })export class TablePipe implements PipeTransform { constructor(private decimalPipe: DecimalPipe) { } transform(field: any,format: Format,formatArg: st
我很乐意帮助将内置管道导入角度为2的自定义管道.
这是我的代码: @Pipe({ name: 'tablePipe' }) export class TablePipe implements PipeTransform { constructor(private decimalPipe: DecimalPipe) { } transform(field: any,format: Format,formatArg: string): any { let formattedField: any = '' switch (format) { case 'number': { formattedField = this.decimalPipe.transform(field,formatArg); break; } } return formattedField; } } export type Format = 'date' | 'string' | 'number'; 这是我得到的错误:
在组件中导入常规自定义管道时,我使用: @Component({ ...,pipes: [MyCustomPipe],... }) 解决方法
为此,您需要将DecimalPipe添加到某处的提供程序
例如 @NgModule({ providers: [DecimalPipe],... }) export class AppModule {} 您还可以将其添加到组件的提供者(您使用管道的组件或祖先组件). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- Angular2基础之表单使用
- scala sbt test在多个项目上运行setup和cleanup命
- 如何获得Scala 2.10反射引用的实际对象?
- angularjs – $http issue – 在md-autocomplete
- 从bash shell脚本中的glob目录内的命令行执行命令
- shell自动安装sublime-text-2
- tips:解决bootstrap-switch 在jqgrid中动态加载
- angularjs中的编译和链接函数之间的区别是什么
- AngularJS:控制器/服务应该是Pascal Case? (在
- angularjs – 如何在Angular 1.5中注入组件路由器
热点阅读