angular-hotel-manager/src/app/star-rating/star-rating.component.ts

29 lines
675 B
TypeScript

import { NgClass, NgFor } from '@angular/common';
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-star-rating',
standalone: true,
imports: [NgClass, NgFor],
templateUrl: './star-rating.component.html',
styleUrl: './star-rating.component.css',
})
export class StarRatingComponent {
@Input() public rating: number = 0;
public getRatingArray(): number[] {
let stars = [];
for (let i = 0; i < 5; i++) {
if (i < this.rating) {
if (i + 0.5 == this.rating) {
stars.push(0.5);
} else {
stars.push(1);
}
} else {
stars.push(0);
}
}
return stars;
}
}