I have a filtered list, within a directive:
<div ng-repeat="item in items | filter:filter | limitTo:5 as filteredItems">
<div ng-bind="item.title"></div>
</div>
<div><span ng-bind="filteredItems.length"></span> items</div>
I wish to access and manipulate the filtered list in the directive's controller. However scope.filteredItems is undefined in the controller.
How can I pass the filtered array to the directive's controller?
You'll be able to get a hold of your filtered array by injecting
$filterinto your controller and leveraging the following, targeting your custom filter offilterThis will include your new array with both filters of
filterandlimitToapplied. Observe the simplistic example to demonstrate thisJSFiddle Link - working example