Angular js: Access data filtered in ng-repeat (ngRepeat) from controller

前端 未结 2 876
无人共我
无人共我 2020-12-31 23:54

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:

2条回答
  •  难免孤独
    2021-01-01 00:50

    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.

提交回复
热议问题