如何使用角度js制作服务器端过滤器

时间:2015-05-18 10:04:48

标签: angularjs

如何使用角度js进行服务器端过滤?我已经尝试了下面的代码,现在我可以进行分页,但我无法进行过滤。

var app = angular.module('myApp', ['ui.bootstrap']);

app.filter('startFrom', function() {
    return function(input, start) {
        if (input) {
            start = +start; //parse to int
            return input.slice(start);
        }
        return [];
    }
});
app.controller('customersCrtl', function($scope, $http, $timeout) {
    $scope.currentPage = 1;
    $http.get('ajax/getCustomers.php?limit=' + $scope.currentPage).success(function(data) {
        $scope.list = data;
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 5; //max no of items to display in a page
        $scope.filteredItems = $scope.list[0].total; //Initially for no filter  
        $scope.totalItems = $scope.list[0].total;
    });
    $scope.setPage = function(pageNo) {
        $scope.currentPage = pageNo;

    };
    $scope.filter = function() {
        $timeout(function() {
            $scope.filteredItems = $scope.filtered.length;
        }, 10);
    };
    $scope.sort_by = function(predicate) {
        $scope.predicate = predicate;
        $scope.reverse = !$scope.reverse;
    };
});

1 个答案:

答案 0 :(得分:0)

我之前遇到过这种情况 - https://masteringmean.com/lessons/471-Building-a-Complex-Single-Page-Application-Part-6 它大约6分钟,但它解释了如何添加$过滤器。它是在另一个应用程序的上下文中,但它很容易遵循。