【问题标题】:How to format MySQL datetime to angular2 useable date format in Ionic 2?如何在 Ionic 2 中将 MySQL 日期时间格式化为 angular2 可用日期格式?
【发布时间】:2016-05-27 14:24:32
【问题描述】:

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

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”

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

【问题讨论】:

    标签: mysql angular ionic2


    【解决方案1】:

    模板网址后缺少逗号

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

    【讨论】:

    • 之后我在控制台中收到错误 Cannot find module '@angular2/core' from 'C:\Users\User\Desktop\tester\app\pipes' 所以我将导入更改为'ionic-angular',现在我收到错误 TypeError: (0 , _ionicAngular.Pipe) is not a function
    • @A.Ilazi 应该是@angular/core,没有2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多