I get the concept of how to get a simple image into the cell like this
<img [src]="element.imageUrl" />
But i am wondering what the best way would be to display a collection of stars. Lets say i have a field called overallRaiting which holds a value of 0 to 5. If the value is 0 i want to show no star , if its 1 then 1 star ,if 2 then 2 stars and so on. Here is what i came up with so far which works but hope there might be better way.
<ng-container matColumnDef="imageUrl">
<th mat-header-cell *matHeaderCellDef> Image Url </th>
<td mat-cell *matCellDef="let element">
<img *ngIf="element.overallRaiting>=1" [src]="element.imageUrl" />
<img *ngIf="element.overallRaiting>=2" [src]="element.imageUrl" />
<img *ngIf="element.overallRaiting>=3" [src]="element.imageUrl" />
<img *ngIf="element.overallRaiting>=4" [src]="element.imageUrl" />
<img *ngIf="element.overallRaiting>=5" [src]="element.imageUrl" />
</ng-container>
Would i have to do a *ngif for each nbr or is the a cleaner more reusable way ?
Ok tried this on
<ng-container matColumnDef="overall_rating">
<th mat-header-cell *matHeaderCellDef> Overall Rating </th>
<td mat-cell *matCellDef="let element">
<ng-container *ngFor="let i of [].constructor(element.overall_rating)">
<img class="star" src="../../assets/images/basic-5-point-gold-star-beveled.jpg" />
</ng-container>
{{element.overall_rating}}
</td>
</ng-container>
Which produces this in doc
<td _ngcontent-snv-c2="" class="mat-cell cdk-column-overall_rating mat-column-overall_rating" mat-cell="" role="gridcell"><!--bindings={
"ng-reflect-ng-for-of": "4"
}--><!----><img _ngcontent-snv-c2="" class="star" src="../../assets/images/basic-5-point-gold-star-beveled.jpg"> 4 </td>