【发布时间】:2019-03-12 10:13:45
【问题描述】:
我创建了星级评分系统。在 Rate 属性中,我将评级保持在 1 到 5 的范围内。我将 Rate 属性分配给了这些值所在的 Stars 数组。
我在正确显示表格中的值时遇到问题。例如,评分值为 5,应该显示 5 颗星,而在我的情况下,它只显示 3。如何解决?
组件:
export class RatingStarComponent implements OnInit {
commentList: Rating[];
stars: number[];
constructor(private productService: CategoriesProductsService, private router: Router ) { }
ngOnInit() {
this.productService.getComment().subscribe(data => {
this.commentList = data;
this.commentList = this.commentList.filter(x => x.ProductId === this.products.Id);
this.stars = this.commentList.map(x => x.Rate);
console.log('Comment List:', this.commentList);
console.log('Stars:', this.stars);
});
}
HTML:
<div class="row" *ngFor="let comment of commentList">
<div class="col-sm-12">
Comment: {{comment.Comment}} <br/>
Your rating: {{comment.Rate}}
</div>
<div class="col-sm-6" >
<ul class="list-inline ratingList" *ngFor="let x of stars">
<li >
<i value="x" class="fa fa-star fa-lg"></i>
</li>
</ul>
</div>
</div>
欢迎任何帮助或建议
【问题讨论】:
-
this.stars = this.commentList.map(x => x.Rate);
-
@AkberIqbal 这不是重复的,至少在标记之前尝试理解问题...... op 的逻辑有问题。
标签: angular typescript