AkAk47
AkAk47

Reputation: 291

Show Message if results are 0

I have a Filter for a Table and want to show no Results if the filter found nothing.
In short the necessary Code:

<th>Keys
<input ng-model="k" id="search" class="form-control" placeholder="Suche...">
            </th>  
<tr dir-paginate="v in result = ($ctrl.langV  | filter:{Name:k}) | orderBy : 'Name' |itemsPerPage: 10">
            <td class="td-keys">{{v.Name}}
            </td>
            <td ng-if="result.length === 0">Keine Ergebnisse</td>

I have found allready here a few Examples:

 <td ng-show="result.length">Keine Ergebnisse</td>  

Is showing me the extra td because results are found. But the opposite for no Results never works. Thx for Solutions :)

Upvotes: 0

Views: 774

Answers (3)

developer033
developer033

Reputation: 24864

At first you have to give an alias to your "results", something like filteredItems, as below:

<tr dir-paginate="v in $ctrl.langV | filter: { Name: k } | orderBy : 'Name' | itemsPerPage: 10 as filteredItems">

Then, you can use it:

<td ng-if="!filteredItems.length">No results</td>

Upvotes: 0

Todd Miller
Todd Miller

Reputation: 301

In the three examples you referenced, they are displaying the no result message outside of the ng-repeat. You are display the no result message inside the ng-repeat. Try taking that statement out of the scope of the ng-repeat and see if it works then.

Upvotes: 0

Thalaivar
Thalaivar

Reputation: 23622

Why don't you use like this... when no results, this would show.

<td ng-if="!result.length">Keine Ergebnisse</td>

Upvotes: 2

Related Questions