I'm still getting the hang of angular and JavaScript OOP, looking to create a reusable component in Angular that can bind all controls to an instance of a JavaScript object. One strange issue I came across is when attempting to filter a collection using a method from a JavaScript object.
The object has a method named filterVisible with this signature:
this.filterVisible = function(item)
When trying to use ng-repeat filtered by this object method:
ng-repeat="item in item1.items | filter: item1.filterVisible"
It doesn't seem to work as expected. However, if I wrap the object method within a $scope method like this:
$scope.filterVisible1 = function(item) {
return ($scope.item1.filterVisible(item));
}
and then update my repeat to:
ng-repeat="item in item1.items | filter: filterVisible1"
It works perfectly fine.
This situation was a bit perplexing, so I've created a plunker to demonstrate. Can someone shed light on why the filter works with the scope method but not directly with the object method?