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

How to format MySQL datetime to angular2 useable date format in Ionic 2?

我正在尝试将 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}} 我得到错误:

Error: Uncaught (in promise): Template parse errors: The pipe 'dateToIso' could not be found

我做错了什么?感谢大家:)

模板后面少了一个逗号url

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