0

Example

So the below template gets loaded as the content for a modal. I can read the scope I've set, but I can't understand how I've not bound the <pagination> to totalItems.

example output

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="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></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'
                    });
                });
            }
        }
    };
});

What gives?!

Gus Crawford
  • 1,017
  • 8
  • 18
  • where you gonna place `my-directive` attribute on html? – Pankaj Parkar May 30 '15 at 14:58
  • @pankajparkar - it's nested in a higher-level template – Gus Crawford May 30 '15 at 15:01
  • @jme11 - what does that object look like? I didn't see the example at https://angular-ui.github.io/bootstrap/#/pagination setting `$scope.totalItems` to an object; it's a numeric. – Gus Crawford May 30 '15 at 15:03
  • @jme11 I found this on another thread http://stackoverflow.com/questions/18642371/checkbox-not-binding-to-scope-in-angularjs - going to try a isolated object with page and count. – Gus Crawford May 30 '15 at 15:12
  • Wait, it looks like you're passing the scope to the modal scope, so $scope.totalItems = $scope.helpPages.length; should work. – jme11 May 30 '15 at 15:20
  • Yeah it really ought to as far as I can tell. I tried wrapping the pagination control values into an object and referencing them from that and still the same result. – Gus Crawford May 30 '15 at 15:21
  • Can you do a plunker? – jme11 May 30 '15 at 15:33
  • http://run.plnkr.co/plunks/CIssyB/ or http://plnkr.co/edit/CIssyB?p=info – Gus Crawford May 30 '15 at 15:49
  • It works in the plunker... it's got to be something to do with the directive. – Gus Crawford May 30 '15 at 15:50
  • yeah `helpContent` is verfied to be an array of objects. As you can see, the `length` of it is referenced from the `$scope` in my textual output. I'm 'plunking' this all into a directive. – Gus Crawford May 30 '15 at 16:02
  • I've done something wrong. The pattern works totally in plunker: This http://plnkr.co/edit/CIssyB?p=preview re-arranges the ui-bootstrap examples into my particular pattern and works. – Gus Crawford May 30 '15 at 16:10
  • I've done something wrong with my particular code. The pattern works totally in plunker: This re-arranges the ui-bootstrap examples into my particular pattern and works. I'm also working on a project using an older version of ui-bootstrap and angular. My plunk tests that too. I also reviewed the changes (there are none to end-programmer use) in `` since ui-b 11.2. http://plnkr.co/edit/xa8vUn?p=preview – Gus Crawford May 30 '15 at 16:17

1 Answers1

2

Edit

I think you misunderstood that total-items is the total pages to be displayed in the pagination control. The total-items is the total number of items in ALL pages. (Guess I should have looked at your question more carefully, but the issue is not that you can't access totalItems, it's that the pagination is showing only one page when you expected it to show 4).

The default value for items-per-page is 10. Therefore, if you only pass in 4 items, it's only going to show 1 page.

Plunker

<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;" items-per-page="1"></pagination>
Community
  • 1
  • 1
jme11
  • 17,134
  • 2
  • 38
  • 48
  • Appreciate the effort; I too got a plunk going with my particular versions of anuglar and ui-bootstrap, that successfully binds the `` in the modal template. I took your recommendation and cleaned up the internal controller. Still no dice! – Gus Crawford May 30 '15 at 16:30
  • Just the same result as before. – Gus Crawford May 30 '15 at 16:36
  • It is the length of the array of pages, check out the pic at the top, the `totalItems` value is exposed on the scope, and evaluates as expected in an angular expression. – Gus Crawford May 30 '15 at 16:39
  • 1
    I figured out your problem, it has nothing to do with your directive. It's how you've set up your pagination control. You need to set items-per-page = 1. Will fix the answer. – jme11 May 30 '15 at 16:50
  • You get a beer and enjoy your Saturday sir! – Gus Crawford May 30 '15 at 16:58