我正在使用AngularJS将数据绑定到我的Laravel应用程序。我还使用Bootstrap-UI进行分页,到目前为止,事情一开始就在一起工作。AngularJS不刷新ng-repeat页面更改
当我切换到第2页时,ng-repeat将不会显示第2页的数据。我已经检查并且$ scope.results随第2页的数据而变化,但ng-repeat不会显示它。它是空白的。
我试过放置$ scope。$ watch,但我总是得到一个错误,告知$摘要已经在进行中。
这里是我的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(引导-UI)
<pagination class="pull-right" ng-change="getResults(currentPage)" ng-model="currentPage" num-pages="numPages" total-items="totalItems" items-per-page="entryLimit"></pagination>
我的角度代码:
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);
});
});
它的作品谢谢!点#1和#2不是原因,这是我尝试粘贴示例代码时的错误(我的代码略有不同)。我必须从ng-repeat中删除startFrom和limitTo,而不是完美的工作。 – Sergio