How to use ng-if with ng-repeat?

There’s probably a better solution, but after reading the replies above, you can try making your own custom filter:

angular.module('yourModule').filter('filterNavItems', function() {
  return function(input) {
    var inputArray = [];

    for(var item in input) {
      inputArray.push(input[item]);
    }

    return inputArray.filter(function(v) { return v.nav; });
  };
});

Then to use it:

<section class="nav">
    <a  ng-repeat="(key, item) in routes | filterNavItems"
        ng-href="https://stackoverflow.com/questions/19235385/{{key}}">
            {{item.label}}
    </a>
</section>

Here’s the Plunker: http://plnkr.co/edit/srMbxK?p=preview

Leave a Comment