angular - Angular——今天的日期和从 API 返回的日期之间的差异
问题描述
我正在处理的网站页面从 API 中提取人们的评论。返回的 JSON 中的一项是评论的创建日期。我想显示评论日期(我已经完成了),但我还想包括该评论是多少天前创建的。我正在使用 *ngFor 循环浏览所有评论。
<div *ngFor="let review of reviews.data.beerReviews.items">
<div>{{review.createdAt | date}}</div> //displays date of the review as expected
//here I want to display the number of days ago the review was made
</div>
我尝试为今天的日期创建一个属性:
today: number=Date.now();
然后我试着让它做数学:
{{today|date - review.createdAt|date}}
它当然不起作用,控制台中的错误:
Parser Error: Unexpected token '-' at column 12 in [{{today|date - review.createdAt|date}}]
我对这一切都很陌生,所以希望我已经解释得很好,谢谢。
解决方案
推荐阅读
- javascript - 允许移动用户将 GPS 数据发送到 mongoose DB 的脚本
- c# - 如何从子进程中的致命错误中拯救父进程
- go - 构造 HTTP POST 请求以包括 req 查询,但请求正文中包含 q 值
- typescript - 在vuejs中提交表单期间的事件类型?
- xamarin.forms - 如何在 iOS 应用顶部为相机和底部为滑动区域留出足够的空间
- visual-studio-code - 使用 Source Code Pro 的黑色代码和无语法高亮显示
- r - Shiny-R 数据集中的多个过滤器,每个新过滤器都会考虑其他过滤器
- python - 如何将现有工作表中的几列复制到同一工作簿中的新工作表中?
- r - 将逻辑矩阵转换为整数矩阵
- python - SqlAlchemy。获取数据库上的最后一个数据