gpt4 book ai didi

javascript - 如何在 Angular 6 中添加计数器?

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:41 25 4
gpt4 key购买 nike

我有一个从服务器抓取评论的功能,我想显示服务器中可用的评论总数。

这是 .ts 文件中的函数:

 this.activeRouter.params.subscribe(params => {
// tslint:disable-next-line:prefer-const
let id = params['id'];
this.userService.getComments(id)
.pipe(
map(data => data.sort((a, b) => new Date(b.localTime).getTime() - new Date(a.localTime).getTime()))
)
.subscribe(data => this.comments = data);
});

这是服务中的get函数

  getComments (id: number) {
return this.http.get<Comment[]>(this.commentsUrl);
}

这是显示评论的html

 <div class="comments-description" *ngFor="let comment of comments">
<span class="comments_count">(353)</span>
<div class="comments-photo">
<img src="https://randomuser.me/api/portraits/men/84.jpg" alt="">
</div>
<div class="comments_wrapper">
<div class="comments_details">
<h1>{{comment.author}}</h1>
<span class="days">1d</span>
</div>
<div class="comments_text">
<p>{{comment.description}} </p>
</div>
</div>
</div>

最佳答案

为什么不简单地使用长度

<span class="comments_count">{{comments.length}}</span>

关于javascript - 如何在 Angular 6 中添加计数器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53042550/

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