Reputation: 1247
Lets say we have this ng-repeat with a text filter :
<input ng-model="searchFilter" type="text">
<ul>
<li ng-repeat="item in items | filter:searchFilter" >
<label>{{item.label}}</label>
</li>
</ul>
<p>Sorry, no result</p>
I am wondering if it is possible to show a message (<p>Sorry, no result</p>
) when a text filter return 0 items in a ng-repeat
?
JSBin here.
Upvotes: 3
Views: 3678
Reputation: 104775
Sure, you can use the following ng-repeat
syntax:
<li ng-repeat="item in filteredItems = (items | filter:searchFilter)" >
<label>{{item.label}}</label>
</li>
<li ng-if="filteredItems.length === 0">No Items Found</li>
JSBin: http://jsbin.com/zepobugexi/2/edit
Upvotes: 17