0

Using AngularJs, i have a double loop to display data, and a filter by year.

When, for a given year, i have no results, i want to display the message "No results...", but because of the double loop, i'm not able to get it to work

Here is a demo http://plnkr.co/edit/OSWSyXk8bnvmj1rFwHJ0?p=preview

The div i want to display when

<div ng-if="personnes.length < 1" class="noresults">No RESULTS</div>

To see an example with no results, choose "2013-2014" in the Year dropdown

Thanks a lot

user
  • 539
  • 1
  • 11
  • 32

1 Answers1

1

Well, this is not so pretty as I would like, but anyways. You could update your html as follows:

<div ng-if="filterArray(resultsPersonnes).length < 1 && $first" class="noresults">No RESULTS</div>

and in your controller create new function:

$scope.filterArray = function(resultsPersonnes) {
    return resultsPersonnes.filter(function(prop) { return prop.fraiss[0].annee == $scope.annee.id; });
}

So basically this just repeats what angular does for you in ng-repeat with filters. See updated Demo.

Ilya Luzyanin
  • 7,910
  • 4
  • 29
  • 49