I need to access data that was already filtered on a template (inside a ng-repeat) from my controller.
Here\'s what I mean:
I have this table in my template:
You can simplify your code with the following:
<tbody>
<tr ng-repeat="person in (filteredPersons = (persons | filter:query))">
<td>{{person.name}}</td>
<td>{{person.gender}}</td>
</tr>
</tbody>
After that, you can get access to $scope.filteredPersons
into controller or {{filteredPersons}}
right into the view :)
I'm not entirely sure, but you can use the filter function in your controller. So try something like:
$scope.$watch('query.gender', function(newValue, oldValue) {
var x = $filter('filter')($scope.persons, $scope.query);
});
x should then contain the same filtered data as in your table I think. Have a look at the docs here: http://docs.angularjs.org/api/ng.filter:filter for some more info.