【发布时间】:2018-09-04 16:17:06
【问题描述】:
我的服务“getList”返回一个项目列表。 我想遍历项目列表并格式化日期。 然后返回格式化的数组。
我当前的尝试没有返回数组中的项目,因为我使用 flatMap 来循环地图中的项目。
我正在使用 angular6 和 rxjs。
我的尝试:
this.list$ = this.service.getList()
.pipe(
flatMap(response => response.items),
map(item => {
item.date = moment(item.date).format('YYYY-MM-DD').toString();
return item;
})
);
【问题讨论】:
-
你可以在模板本身中使用管道格式化日期
-
@mohammedsameen 你能举个例子吗?
-
类似:{{list$ |异步 |日期:'yyyy-MM-dd'}} angular.io/api/common/DatePipe
-
工作了,谢谢。不过最好不要使用 RXJS 来做到这一点
标签: javascript angular typescript rxjs