M
M
Mike Diam2016-06-30 12:16:48
Angular
Mike Diam, 2016-06-30 12:16:48

How to use angular.filter in controller function?

When select changes, the data type and value are passed to the function (ng-change="sortEvents(type, value)")
In the function itself, you need to filter by all elements of $scope.events, selecting all elements with a "state" value equal to "NSW"

$scope.sortEvents = function(type, value, $scope, $filter) {
            $scope.events = $filter('filterBy')($scope.events, ['state'], 'NSW');
            console.log($scope.events);
        }

But the console writes prntscr.com/bmyj74
Angular filter through ng-repeat works correctly, in app.js it is also written in dependencies as needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-06-30
@healqq

why do you need $filter at all.
Make it simple

array.filter(function(item) { item.state ==='NSW'});
and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question