I created star rating system. In the Rate property, I keep the rating on a scale of 1 to 5. I assigned the Rate property to an Stars array in which these values are.
I have a problem with correctly displaying values from the table. For example, the rating value is 5 and should display 5 stars and in my case it displays only 3. How to solve it?
Component:
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> Any help or sugestion is welcome