【问题标题】:Angular 2 and DatePipe millisecondsAngular 2 和 DatePipe 毫秒
【发布时间】:2017-01-14 20:00:32
【问题描述】:

我有一个谷歌地图,我点击一个单元。当我单击一个单元时,我会通过服务从 REST 中获取有关该单元的一些数据。然后我得到 StartToday 女巫在几秒钟内。然后我想将其显示为HH:mm:ss。我的 StartToday 返回 360。

{{unit.StartToday * 1000}} // Works is 360000
{{360000 | date: "HH:mm:ss"}} // Works is 01:06:00
{{unit.StartToday * 1000 | date: "HH:mm:ss"}} // Does not work 

但我收到此错误:

例外:./MapComponent 类 MapComponent 中的错误 - 内联模板:11:12 原因:管道“DatePipe”的参数“NaN”无效 原始异常:管道“DatePipe”的参数“NaN”无效

【问题讨论】:

    标签: angular


    【解决方案1】:

    你应该试试:

    {{ (toNumber(unit.StartToday) * 1000) | date: "HH:mm:ss" }}
    

    并确保 unit.StartToday 是一个数字:

    toNumber(input_to_number:any){
     return Number(input_to_number);
    }
    

    https://plnkr.co/edit/ficVwQ2DO9E8jYpn4V4a?p=preview

    祝你好运!

    【讨论】:

    • 你确定 unit.StartToday 是一个数字吗?打印时看到的内容:{{unit.StartToday}} ?
    • 它显示 360。也是我可以在其余网址上设置的值。我应该作为整数传递吗?或者当角度尝试管道它时,值可能没有准备好。
    猜你喜欢
    • 2017-04-29
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多