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
$filter
into your controller and leveraging the following, targeting your custom filter offilter
This will include your new array with both filters of
filter
andlimitTo
applied. Observe the simplistic example to demonstrate thisJSFiddle Link - working example