【发布时间】:2015-07-10 22:52:28
【问题描述】:
我正在使用 AngularJS 将数据绑定到我的 Laravel 应用程序。我也在使用 Bootstrap-UI 进行分页,到目前为止,一切都在协同工作。
当我切换到第 2 页时,ng-repeat 不会显示第 2 页中的数据。我已经检查过 $scope.results 正在随着第 2 页中的数据而变化,但 ng-repeat 不会显示它.一片空白。
我尝试放置 $scope.$watch,但总是收到错误消息,提示 $digest 已在进行中。
这是我的 HTML 代码:
<tr ng-repeat="result in filtered = results | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit" class="results-table">
<td class="text-center">
[[ result.id ]]
</td>
<td>
[[ result.name ]]
</td>
<td>
[[ result.email ]]
</td>
<td>
[[ result.cpf ]]
</td>
<td class="text-center">
<span class="label label-sm" ng-class="{true: 'label-success', false: 'label-danger'}[result.active == 'Ativo']">
[[ result.active ]]
</span>
</td>
<td class="text-center">
<a href="#"><i class="fa fa-pencil font-blue"></i></a>
<a href="#"><i class="fa fa-remove font-red-flamingo"></i></a>
</td>
</tr>
我的分页 HTML (bootstrap-ui)
<pagination class="pull-right" ng-change="getResults(currentPage)" ng-model="currentPage" num-pages="numPages" total-items="totalItems" items-per-page="entryLimit"></pagination>
还有我的 Angular 代码:
var app = angular.module('prime', ['ngSanitize','ngResource','angular-loading-bar','ngAnimate','ui.bootstrap'],
function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
});
app.factory('JsonService', function ($resource,model) {
return $resource('/api/users/?page=:page',{page: "@page"});
});
app.filter('startFrom', function () {
return function (input, start) {
if (input) {
start = +start;
return input.slice(start);
}
return [];
};
});
app.controller('ResultsController', function($scope, $http, JsonService, filterFilter) {
$scope.results = [];
$scope.search = [];
$scope.currentPage = 1;
$scope.entryLimit = 10; // itens por pagina
$scope.init = function() {
JsonService.get({}, function (response) {
$scope.results = response.data;
$scope.totalItems = response.total;
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
}, function (error) {
$scope.results = [];
});
};
$scope.resetFilters = function () {
$scope.search = [];
};
// runs $watch on the search field
$scope.$watch('search', function (newVal, oldVal) {
$scope.filtered = filterFilter($scope.results, newVal);
$scope.totalItems = $scope.filtered.length;
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
$scope.currentPage = 1;
}, true);
$scope.$watch('currentPage', function(newPage) {
$scope.init($scope.numberPage);
});
});
【问题讨论】:
标签: angularjs