Prevent filter service from invoking on digest cycle

I left a thread yesterday (AngularJS filter service on loop) trying to understand why my filter service was being called on a loop. After some further debugging and research I found out from AngularJS API that the filter is called on each digest cycle.

In templates, filters are only executed when their inputs have changed. This is more performant than executing a filter on each $digest as is the case with expressions.

There are two exceptions to this rule:

  1. In general, this applies only to filters that take primitive values as inputs. Filters that receive Objects as input are executed on each $digest, as it would be too costly to track if the inputs have changed.

  2. Filters that are marked as $stateful are also executed on each $digest. See Stateful filters for more information. Note that no AngularJS core filters are $stateful.

So I’m using ngIdle which has a service that sends a request to notify the back-end there is still user activity.

$scope.$on('Keepalive', function() {

Keepalive is broadcasted every 30 seconds on a $timeout function in the app.config file.

Looking into $stateful filters, I amended my filter like so:

angular.module('ppApp').filter('testFilter', testFilter);

function testFilter() {
    function testFilter(movies, genres) {
        console.log(movies, genres)
        var items = {
             genres: genres,
            out: []
        angular.forEach(movies, function (value, key) {
            if (this.genres[value.genre] === true) {
        }, items);
        return items.out;
    testFilter.$stateful = true;
    return testFilter;

However the problem persists that everytime that $http request is made, the digest cycle runs and it causes the filter function to be called.


How do I prevent this behaviour from happening? Either stopping the digest cycle on this specific $http request OR amending my filter so it is only called when a user inputs data?

Source: New feed
Source Url Prevent filter service from invoking on digest cycle