gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:12:51 26 4
gpt4 key购买 nike

我正在尝试将如下所示的 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]
})

关于mysql - 如何在 Ionic 2 中将 MySQL 日期时间格式化为 angular2 可用日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37485936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com