错误:
Error: Template parse errors: The pipe 'datefromiso' could not be found
管道:
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({
name: 'datefromiso'
})
export class DateFromISO implements PipeTransform {
transform(value: any, args: string[]): string {
if (value) {
var date = value instanceof Date ? value : new Date(value);
return date.getDate() + '/' + (date.getMonth()+1) + '/' + (date.getYear()+1900);
}
}
}
应用模块:
import { DateFromISO } from './pipes/date-from-iso';
...
@NgModule({
bootstrap: [ App ],
declarations: [
App,
ErrorComponent,
DateFromISO
]
HTML:
<div class="pull-right">{{entity.ts | datefromiso}}</div>
entity.ts
是 ISO 字符串。怎么了?
还有一个问题:是否有更好的方法将 ISO 字符串转换为带有 angular2 的 html 中的语言环境日期?
提前致谢。
最佳答案
您需要将包含 DateFromISO
的模块添加到您使用它的每个模块的 imports
中。
因此,建议创建一个包含管道和其他可重用指令和组件的功能模块,然后将此模块添加到所有模块中应该可用的 imports
。
需要将管道和其他可重用组件和指令添加到此功能模块中的declarations
和exports
。
关于javascript - 找不到 Angular2.0.0 管道 '',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40341375/