【发布时间】:2017-03-13 11:43:40
【问题描述】:
错误:
错误:模板解析错误:管道 'datefromiso' 不能 找到了
管道:
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 字符串。怎么了?
还有一个问题:是否有更好的方法可以使用angular2将ISO字符串转换为html中的语言环境日期?
提前致谢。
【问题讨论】:
-
HTML 是在
App或ErrorComponent还是另一个模块中的某个组件? -
组件在另一个模块中,所以我需要在那个模块中声明它?
标签: javascript angular typescript