I am working on a component where I need to show different icons based on a status:
component.html
<app-form-row label="Status">
<span>
<i *ngIf="getStatus === 'READY'" class="check circle outline icon green"></i>
<i *ngIf="getStatus === 'UPDATING'" class="notched circle loading icon orange"></i>
<i *ngIf="getStatus === 'FAILED'" class="times circle outline icon red"></i>
</span>
</app-form-row>
component.ts
get getStatus(): string {
return this.data.status;
}
Another approach is to move the condition in TS.
component.html
<app-form-row label="Status">
<span>
<i [ngClass]=“classByStatus"></i>
</span>
</app-form-row>
component.ts
get classByStatus(): string {
return {
'READY': 'check circle outline icon green',
'UPDATING': 'notched circle loading icon orange',
'FAILED': 'times circle outline icon red'
}[this.data.status];
}
What are the pros and cons for each approaches?
Any other way to solve this use case?
ngSwitch, but use whichever you prefer.