I am getting data from JSON file instead of database. I am trying to give color to the Icon based on the value of status in JSON for example [if green? class1:class2] below is my code.
My HTML file
<ng-container matColumnDef="status" [ngClass] = "{'color1': row.status ===
'GREEN', 'color2': row.status === 'RED'}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Status</th>
<td mat-cell *matCellDef="let row" class="color1">{{row.status}}</td>
<td mat-cell *matCellDef="let row" class="color2">{{row.status}}</td>
</ng-container>
Below is my JSON file.
data:[
{
"name": "xyz",
"address": "post",
"status": "GREEN"
},
{
"name": "xyz1",
"address": "post1",
"status": "RED"
}
],
"count" : 2
}
This is my CSS
.color1{
color: green;
}
.color2{
color: red;
}
** I could not able to change color of status icon. And I got this error **
ERROR TypeError: Cannot read property 'status' of undefined