user499054
user499054

Reputation:

Checking if an ng-repeat yields empty set after filter

I'm trying to do this:

Is there a way to check what the filter yields after the "basic" filter, so I can perform a $http call back to the server? Is there a "filter" that is built-in to angular that I can call up?

I've tried watching the variable:

  $scope.$watch('filtered_notes', function() {
    // can't do this
  });

Where ng-repeat="note in filtered_notes = (notes | orderBy:['-note_time']|filter:noteFilter|limitTo:limit)"

But, it throws an error: Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

Upvotes: 1

Views: 309

Answers (1)

Maxim Shoustin
Maxim Shoustin

Reputation: 77930

You can create custom filter like following example

HTML

<div ng-repeat="note in filtered_notes |  myCustomFilter:theInput">

custom filter JS

 iApp.filter('myCustomFilter', function() {
   return function( notes, input) {
    var filtered = [];

    angular.forEach(notes, function(item) {
       if(/* do any condition with 'input' */) {
          filtered.push(item);
        }

    });

    if(filtered.length >= 5 ){
         /* do HTTP call or use $broadcast to trigger HTTP call*/
    }

    return filtered;
  };

Upvotes: 1

Related Questions