I'm trying to write a generic filter function like this:
var filterGenerator = function(ids) {
return function (o) {
return _.contains(ids, o.id); // using lodash _.contains
}
}
I expose this on the scope like so:
$scope.myFilter = filterGenerator($scope.listOfIds);
It works on initial page load in the partial (using o in objects | filter:myFilter
), but when $scope.listOfIds
changes, I would expect the filtered values to change as well - however, they do not. I suspect that when I call filterGenerator($scope.listOfIds)
, the returned lambda is getting a separate scoped version of $scope.listOfIds
that never changes, but I'm unsure how to get around this. How would I go about making sure that the lambda sees any changes to the list?