【发布时间】:2015-08-13 09:03:22
【问题描述】:
示例
所以下面的模板被加载为模态的内容。我可以阅读我设置的范围,但我无法理解我没有将<pagination> 绑定到totalItems。
模板.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'
});
});
}
}
};
});
什么给了?!
【问题讨论】:
-
你要把
my-directive属性放在html的什么地方? -
@pankajparkar - 它嵌套在更高级别的模板中
-
@jme11 - 该对象是什么样的?我没有看到angular-ui.github.io/bootstrap/#/pagination 将
$scope.totalItems设置为对象的示例;这是一个数字。 -
@jme11 我在另一个线程stackoverflow.com/questions/18642371/… 上找到了这个 - 将尝试使用页面和计数的孤立对象。
-
等等,看起来你正在将范围传递给模态范围,所以 $scope.totalItems = $scope.helpPages.length;应该工作。
标签: javascript angularjs pagination angular-ui-bootstrap