【发布时间】:2017-07-14 08:29:03
【问题描述】:
在我的应用程序中,我需要一个全局自定义管道,我尝试按照angular pipe 实现它 但我总是看到这个错误
模板解析错误:找不到管道“formatdate”
formatdate.pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'formatdate'
})
export class FormatdatePipe implements PipeTransform {
transform(dateJson: any, args?: any): any {
.
//code...
.
return dateJson;
}
}
}
app.module
import { FormatdatePipe } from './shared/pipes/formatdate.pipe';
@NgModule({
declarations: [
AppComponent, FormatdatePipe
],
如果我将它导入我的所有模块而不是主体 app.module 中,这个管道可以工作,我是否需要一个常规管道模块或其他东西
【问题讨论】:
-
你在哪里使用它?
-
在许多子组件中
-
你需要导出管道,然后在其他模块中使用该模块
-
你有例子吗?
标签: angular angular2-custom-pipes