convert time stamp to Date inside angular expression like {{new Date(timestamp)}}

后端 未结 6 1591
旧时难觅i
旧时难觅i 2021-02-05 11:49

Today I found that\'s it\'s not working to convert for a date inside angular expression.

So I just making something like

{{new Date(elem.times         


        
6条回答
  •  既然无缘
    2021-02-05 11:58

    Because angular expressions do not accept arbitrary Javascript code, including creating new objects. What you are looking for is called angular filters, they were specifically designed for this case.

    So instead of

    {{new Date(elem.timestamp)}}

    you should write

    {{elem.timestamp | date: 'yyyy-MM-dd'}}

    More info on date filter can be found here. More on filters in general can be found here.

提交回复
热议问题