gpt4 book ai didi

angularjs - Angular UI Bootstrap 中的分页抛出 "Error: [$compile:nonassign]"

转载 作者:行者123 更新时间:2023-12-02 22:14:18 27 4
gpt4 key购买 nike

我正在使用 Angular Bootstrap UI 分页指令的相当简单的实现,但我不断收到一个我无法弄清楚的错误。以下是相关片段:

<ul>
<li ng-repeat="todo in filteredIdeas">
{{todo}}
</li>
</ul>
<pagination ng-model="currentPage" total-items="totalIdeas"></pagination>

以下是 Controller 中我的 $scope 的相关部分:

// Set watch on pagination numbers
$scope.$watch('currentPage + numPerPage', function() {

var begin = (($scope.currentPage - 1) * $scope.numPerPage);
var end = begin + $scope.numPerPage;

$scope.filteredIdeas = $scope.ideasData.slice(begin, end);

});


// Data
$scope.ideasData = [];

for (var i = 0; i < 100; i++) {
$scope.ideasData.push('To do ' + i);
}

$scope.filteredIdeas = [];
$scope.currentPage = 1;
$scope.numPerPage = 10;
$scope.totalIdeas = $scope.ideasData.length;

分页设置正确,但这是我在尝试单击下一页(或与此相关的任何页面)时收到的错误:

Error: [$compile:nonassign] Expression 'undefined' used with directive 'pagination' is non-assignable!

如果我理解正确的话,这表明我在双向绑定(bind)中使用了不正确的东西?能够复制此 Plunkr 中的错误:http://plnkr.co/edit/uyWQXPqjLiE4qmQLHkFy

有人对我做错了什么有什么想法吗?

最佳答案

使用ng-model的能力于 ui-bootstrap-tpls-0.11.0.js 中引入,如 changelog 中所述:

Both pagination and pager are now integrated with ngModelController.
* page is replaced with ng-model
* on-select-page is removed since ng-change can now be used
Before:
<pagination page="current" on-select-page="changed(page)" ...></pagination> After:
<pagination ng-model="current" ng-change="changed()" ...></pagination>

由于您正在使用ui-bootstrap-tpls-0.10.0.min.js ,您需要使用旧语法 - 与 page而不是ng-model :

<pagination page="currentPage" total-items="totalIdeas"></pagination>

关于angularjs - Angular UI Bootstrap 中的分页抛出 "Error: [$compile:nonassign]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23419059/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com