Filtering code via the ng-reapet :

 var taskApp = angular.module('task', []); <div class="item-block-lio" ng-repeat="todo in tasks | orderBy:predicate:reverse | sortField:status track by $index" ng-cloak> //сам фильтр, который вызывает ошибку taskApp.filter('sortField', function (){ var filtered = []; return function(items, status) { for (var i = 0; i < items.length; i++) { var item = items[i]; if (items[i].status == status) { filtered.push(item); } } return filtered; } }); 

As a result, an error occurs: 10 $digest() iterations reached. Aborting! 10 $digest() iterations reached. Aborting!

Code that returns an array of objects

 $scope.get_tasks = function(){ $http.post('/Task/default/index', {type:$scope.model.type}).success(function(data) { //DataCache.put('tasks', data); // $scope.tasks = data; angular.forEach(data, function(task){ task.cost = Number(task.cost); task.second = Number(task.second); task.status = Number(task.status); $scope.tasks.push(task); }); }); 

    1 answer 1

     taskApp.filter('sortField', function (){ var filtered = []; return function(items, status) { 

    You essentially got a global array. Each filter call adds elements to this array. Transfer the array declaration for the result inside the filter function.


     track by $index 

    This is not necessary for objects.

    • When I remove it, the error Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys generally appears Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys and also error 10 $digest() iterations reached. Aborting! 10 $digest() iterations reached. Aborting! - modelfak
    • @modelfak, make an example on jsfiddle or in a question in the form of a snippet. - Qwertiy
    • @modelfak, though no, not necessary. I realized what the joint. - Qwertiy
    • OK, while I added the code which returns the array - modelfak
    • one
      Thanks for the help! - modelfak