0

I have this:

     <div class="row" ng-repeat="(promptId, q) in (categoryFilteredObj 
      = (categoryObj | custom:searchText:selectAllCheckbox:answeredCheckbox))">

Everything is working fine. But the filter only seems to be invoked when the searchText changes.

How can I force the filter to be evaluated? I could change searchText "artificially", but that wouldn't be the right way to do it.

I would hope that if I change the values for -

selectAllCheckbox

or

answeredCheckbox

that the filter would be re-evaluated, but that does not appear to be the case!

In other words: what I am looking to do is re-invoke this ng-repeat functionality, so that the filter gets re-evaluated, because I have just made changes to the state in my program, and I want the list of objects to change to reflect the state change. Currently, however, the ng-repeat list does not change and the filter does not get hit (I checked the logs). I'd like to somehow "force" the ng-repeat and filter to be re-evaluated. I don't think $scope.$apply() works for this.

Alexander Mills
  • 1
  • 80
  • 344
  • 642

1 Answers1

1

It is working fine for me. Probably you made logic mistake or filter's code throw error or filter's parameters were not actually changed:

angular.module('app', []).controller('MyController', ['$scope', function($scope) {
    $scope.input = {}
}]).filter('myFilter', function(){
  return function(input, param1, param2, param3){
    input.param1 = param1;
    input.param2 = param2;
    input.param3 = param3;
    return input
  }
})
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>

<body ng-app="app">
  <div ng-controller="MyController">
    <input type='text' ng-model='param1' ng-init='param1 = 1'/>
    <input type='text' ng-model='param2' ng-init='param2 = 2'/>
    <input type='text' ng-model='param3' ng-init='param3 = 3'/>
    <ul>
      <li ng-repeat='(key, val) in (obj = (input | myFilter : param1 : param2: param3))'>key: {{key}}, val: {{val}}</li>
    </ul>
  </div>
</body>
Slava Utesinov
  • 12,921
  • 2
  • 16
  • 25