I've been trying to create a custom filter for table data, but when doing so, when logging to the console the filter function was being called on an infinite loop/
I then decided to run a test with separate data, with a simple filter on the same page to see if the issue persisted and it does, copied from here How to filter multiple values (OR operation) in angularJS.
<div ng-init="movies = [
{title:'Man on the Moon', genre:'action'},
{title:'Meet the Robinsons', genre:'family'},
{title:'Sphere', genre:'action'}
];" >
<input type="checkbox" ng-model="genrefilters.action" />Action
<br />
<input type="checkbox" ng-model="genrefilters.family" />Family
<br />{{genrefilters.action}}::{{genrefilters.family}}
<ul>
<li ng-repeat="movie in movies | bygenre:genrefilters">{{movie.title}}: {{movie.genre}}</li>
</ul>
</div>
angular.module('ppApp').
filter('bygenre', function () {
return function (movies, genres) {
console.log('hello')
var items = {
genres: genres,
out: []
};
angular.forEach(movies, function (value, key) {
if (this.genres[value.genre] === true) {
this.out.push(value);
}
}, items);
return items.out;
};
});
The filter is still on loop in my application. I tested the provided code in a plnkr and it worked fine.
UPDATE
So debugging the script in console a component
service was being used to update the time. Completely separate from the controller I am using for filtering the table. On the $timeout
function I was using it seemed to be calling the digest
cycle every time it made the request for the new time.
Question
Why is the filter service being called when a $timeout
service is called, but no other controllers or other services?