separ1
separ1

Reputation: 205

How to use filter in controller?

I am using a scope variable called "sampledata" in controller. I am displaying data in view using filters on the same:-

<div ng-repeat="value in sampledata|orderBy:sortType | filter:   {label:filter_one} | filter: {name_filter: filterName}">
</div>

I want to filter the data in the same way in controller as well. How can i do the same?

Upvotes: 1

Views: 39

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136134

You could use this by inject $filter dependency in controller function

function DoFilter() {
    var orderedBy = $filter('orderBy')($scope.sampledata, $scope.sortType);
    returned $filter('filter')(orderedBy,{label: $scope.filter_one, name_filter: $scope.filterName})
}

Upvotes: 2

Related Questions