Angular.js. How to count ng-repeat iterations which satisfy the custom filter

ng-repeat expression allows filtered results to be assigned to a variable. This variable will be accessible from current scope so you can use it in same scope anyway you want: <p>Number of filtered items: {{filteredItems.length}}</p> <div ng-show=”filteredItems.length > 0″ ng-repeat=”item in filteredItems = (items | notEmpty)” > {{$index}} </div>

Angular ng-repeat conditional wrap items in element (group items in ng-repeat)

You can use groupBy filter of angular.filter module. so you can do something like this: usage: collection | groupBy:property use nested property with dot notation: property.nested_property JS: $scope.players = [ {name: ‘Gene’, team: ‘alpha’}, {name: ‘George’, team: ‘beta’}, {name: ‘Steve’, team: ‘gamma’}, {name: ‘Paula’, team: ‘beta’}, {name: ‘Scruath’, team: ‘gamma’} ]; HTML: <ul ng-repeat=”(key, value) … Read more

Custom sort function in ng-repeat

Actually the orderBy filter can take as a parameter not only a string but also a function. From the orderBy documentation: https://docs.angularjs.org/api/ng/filter/orderBy): function: Getter function. The result of this function will be sorted using the <, =, > operator. So, you could write your own function. For example, if you would like to compare cards … Read more

AngularJS – How to structure a custom filter with ng-repeat to return items conditionally

Filters don’t work on individual items in the array, they transform the entire array into another array. userApp.filter(‘matchAccessLevel’, function() { return function( items, userAccessLevel) { var filtered = []; angular.forEach(items, function(item) { if(userAccessLevel >= item.minAccess) { filtered.push(item); } }); return filtered; }; }); See this plnkr **always inspect the arguments to a function. It’s not … Read more

How to filter (key, value) with ng-repeat in AngularJs?

Angular filters can only be applied to arrays and not objects, from angular’s API – “Selects a subset of items from array and returns it as a new array.” You have two options here: 1) move $scope.items to an array or – 2) pre-filter the ng-repeat items, like this: <div ng-repeat=”(k,v) in filterSecId(items)”> {{k}} {{v.pos}} … Read more

Angular ng-repeat Error “Duplicates in a repeater are not allowed.”

The solution is actually described here: http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ AngularJS does not allow duplicates in a ng-repeat directive. This means if you are trying to do the following, you will get an error. // This code throws the error “Duplicates in a repeater are not allowed. // Repeater: row in [1,1,1] key: number:1″ <div ng-repeat=”row in [1,1,1]”> … Read more