为什么 <paginator> 没有绑定到 $scope?
Why is <paginator> not binding to $scope?
例子
所以下面的模板被加载为模式的内容。我可以阅读我设置的范围,但我不明白我为什么没有将 <pagination>
绑定到 totalItems
。
Template.html
<div class="modal-header">
<h3 class="modal-title">{{$parent.helpName}}</h3>
</div>
<div class="modal-body">
Page {{currentPage }} of {{totalItems}}
<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»"></pagination>
<div data-ng-show="page.pageNumber == currentPage" data-ng-repeat="page in $parent.helpPages">
<ul tabset typeof="pills">
<li tab data-ng-repeat="subPage in page.pills" data-heading="{{subPage.tabTitle}}">
<div class="panel panel-default">
<div class="panel-body" style="overflow:auto;" data-ng-bind-html="subPage.pillDiv">
</div>
</div>
</li>
</ul>
</div>
</div>
Controller.js
app.directive('myDirective', function factory (){
return {
restrict: 'A', // IE8 doesn't support 'custom tags'
template:'<a ng-hide="!overlayName" class="btn btn-primary" ng-click="showHelp(overlayName)">Need Help <i class="fa fa-question-circle"></i></a>',
controller: function overlayCtrl ($scope, $modal, data) {
// [A] overlay control properties
$scope.helpModal = null;
$scope.overlayName = __hasOverlay($scope.$parent.step.shortDesc); // Right now, look up the overlay by the shortDesc
if ($scope.overlayName) $scope.overlayName = $scope.overlayName.help;
// [B] overlay control methods
$scope.showHelp = function (name) {
data.getHelpOverlay(name).then(function (helpContent) {
$scope.helpPages = helpContent;
$scope.helpName = name;
$scope.helpModal = $modal.open({
scope:$scope, controller:function ($scope, $sce) {
// the scope I'd expect <pagination>'s model to bound on
$scope.currentPage = 1;
$scope.totalItems = $scope.$parent.helpPages.length;
// other code...
},
templateUrl:'app/steps/templates/helpOverlay.html',
size:'lg'
});
});
}
}
};
});
什么给了?!
编辑
我想你误会了total-items就是分页控件要显示的总页数。项目总数是 ALL 页中的项目总数。 (我想我应该更仔细地看看你的问题,但问题不是你不能访问 totalItems,而是分页只显示一页,而你期望它显示 4)。
items-per-page 的默认值为 10。因此,如果您只传入 4 个项目,它只会显示 1 页。
Plunker
<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»" items-per-page="1"></pagination>
例子
所以下面的模板被加载为模式的内容。我可以阅读我设置的范围,但我不明白我为什么没有将 <pagination>
绑定到 totalItems
。
Template.html
<div class="modal-header">
<h3 class="modal-title">{{$parent.helpName}}</h3>
</div>
<div class="modal-body">
Page {{currentPage }} of {{totalItems}}
<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»"></pagination>
<div data-ng-show="page.pageNumber == currentPage" data-ng-repeat="page in $parent.helpPages">
<ul tabset typeof="pills">
<li tab data-ng-repeat="subPage in page.pills" data-heading="{{subPage.tabTitle}}">
<div class="panel panel-default">
<div class="panel-body" style="overflow:auto;" data-ng-bind-html="subPage.pillDiv">
</div>
</div>
</li>
</ul>
</div>
</div>
Controller.js
app.directive('myDirective', function factory (){
return {
restrict: 'A', // IE8 doesn't support 'custom tags'
template:'<a ng-hide="!overlayName" class="btn btn-primary" ng-click="showHelp(overlayName)">Need Help <i class="fa fa-question-circle"></i></a>',
controller: function overlayCtrl ($scope, $modal, data) {
// [A] overlay control properties
$scope.helpModal = null;
$scope.overlayName = __hasOverlay($scope.$parent.step.shortDesc); // Right now, look up the overlay by the shortDesc
if ($scope.overlayName) $scope.overlayName = $scope.overlayName.help;
// [B] overlay control methods
$scope.showHelp = function (name) {
data.getHelpOverlay(name).then(function (helpContent) {
$scope.helpPages = helpContent;
$scope.helpName = name;
$scope.helpModal = $modal.open({
scope:$scope, controller:function ($scope, $sce) {
// the scope I'd expect <pagination>'s model to bound on
$scope.currentPage = 1;
$scope.totalItems = $scope.$parent.helpPages.length;
// other code...
},
templateUrl:'app/steps/templates/helpOverlay.html',
size:'lg'
});
});
}
}
};
});
什么给了?!
编辑
我想你误会了total-items就是分页控件要显示的总页数。项目总数是 ALL 页中的项目总数。 (我想我应该更仔细地看看你的问题,但问题不是你不能访问 totalItems,而是分页只显示一页,而你期望它显示 4)。
items-per-page 的默认值为 10。因此,如果您只传入 4 个项目,它只会显示 1 页。
Plunker
<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»" items-per-page="1"></pagination>