Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //COMPONENT
- export class StarRatingComponent implements OnInit {
- @Input() userId: number;
- // vecchio array che usavo prima del refactor
- ratingArray:string[] = [];
- // Observable da usare come array
- ratingArray$ = new BehaviorSubject<string>(null);
- yellowStar:string = "/assets/images/yellow-star.jpg";
- greyStar:string = "/assets/images/grey-star.jpg";
- subscription;
- constructor(private userService:UserService, public ratingService:RatingService) { }
- ngOnInit(): void {
- const observableRating:Observable<any> = this.ratingService.getRating(this.userId);
- this.subscription = observableRating
- .pipe(
- filter( data => data['count'] === 0)
- ).subscribe({
- next:data => {
- for(let k=0;k<=4;k++){
- if(condizione){
- //metodo attuale che mi da errore nel template
- this.ratingArray$.next(this.greyStar);
- //vecchio metodo prima del refactor
- this.ratingArray[k] = this.greyStar;
- } else {
- //metodo attuale che mi da errore nel template
- this.ratingArray$.next(this.yellowStar);
- //vecchio metodo prima del refactor
- this.ratingArray[k] = this.yellowStar;
- }
- }
- }
- });
- }
- //TEMPLATE
- <div class="ratingStars" *ngFor="let rat of (ratingArray$ | async);let i = index">
- <img src="{{rat}}">
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement