如何在Ionic 2中将MySQL datetime格式化为angular2可用日期格式?

时间:2016-05-27 14:24:32

标签: mysql angular ionic2

我正在尝试将一个如下所示的mysql日期时间格式化为: 2016-05-27 20:17:45 为angular2的可用日期格式。在阅读了一些评论后,我可以创建一个自定义管道:

import {Pipe} from 'angular2/core';

@Pipe({
    name: 'dateToIso'
})
export class DateToIso {
    transform(value, args) {
        let newValue = new Date(value).toISOString();
        return newValue;
    }
}

然后我将管道导入到使用它的页面,并在装饰器中定义它以在HTML文件中使用它。

import {DateToIso} from '../../pipes/date-ToIso';
...
@Page({
    templateUrl: 'build/pages/page1/page1.html'
    pipes: [DateToIso]
})

在HTML文件中使用新创建的管道时:{{ post[2] | dateToIso}}我收到错误:

  

错误:未捕获(在承诺中):模板解析错误:管道   ' dateToIso'无法找到

我做错了什么?感谢所有人:)

1 个答案:

答案 0 :(得分:2)

模板网址

后缺少逗号
@Page({
    templateUrl: 'build/pages/page1/page1.html',  // << this comma here
    pipes: [DateToIso]
})