Santanu Bhattacharjee Santanu Bhattacharjee - 5 months ago 10
AngularJS Question

how to add a condition in ng-repeat?

Here is my html table

<table>
<tbody>
<tr class="unread" ng-repeat="CU in InboxList">
<td class="text-right mail-date">{{CU.time}}</td>
</tr>

<tr class="read">
<td class="text-right mail-date">12:00 pm</td>
</tr>
</tbody>
</table>


here in my html table there are two tr class one is tr class="read" and other is class="unread" i have already binded tr class="unread".now i want to check a condition if {{cu.isread=0}} then tr class read will bind otherwise tr class unread will bind.how to do this?

Answer

You could do this with ng-class

Example:

ng-class="(cu.isread === 0)  ? 'unread' : 'read'"