I am trying to do this
{% if collection %}
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
{% else %}
<tr>
<td colspan="3">No items in collection</td>
</tr>
{% endif %}
but I am getting an error saying collection variable is not defined. What's the correct syntax to do that?
Try keeping it all in angular logic
<tbody ng-if="collection">
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
<tbody ng-if="!collection || collection.length==0">
<tr>
<td colspan="3">No items in collection</td>
</tr>
</tbody>
Try below snippet
<tbody ng-if="collection.length > 0">
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
<tbody ng-if="!collection || collection.length==0">
<tr>
<td colspan="3">No items in collection</td>
</tr>
</tbody>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.