Wednesday, 6 May 2015

how to call angular filter from controller (or javascript)




function ngController($scope,$filter){
    $scope.name = "aaaa";
    $scope.age = "32";

     $scope.result = $filter('lowercase')($scope.name);
}


Filter in html:
<tr ng-repeat="item in dataset | filter:searchText">
In controller:

function ngController($scope,$filter){
    $scope.dataset = ["xxx","xx"];

     $scope.result = $filter('filter')($scope.dataset,$scope.searchText);
}

Orderby in html:

<tr ng-repeat="friend in friends | orderBy:predicate:reverse">
In controller:


function ngController($scope,$filter){
    $scope.dataset = ["xxx","xx"];

     $scope.result = $filter('orderBy')($scope.dataset, $scope.predicate,$scope.reverse);
}









No comments:

Post a comment