2015-09-22 65 views
1

查看ui-bootstrap分頁模板,我不明白在ng-class中使用ngDisabled。我正在幫助理解這一點。在ng-class中使用ngDisabled

我查看了'PaginationController',ngDisabled不是一個scope屬性,它是否引用了ng-disabled指令?

<ul class="pagination"> 
    <li ng-if="::boundaryLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-first"><a href ng-click="selectPage(1, $event)">{{::getText('first')}}</a></li> 
    <li ng-if="::directionLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-prev"><a href ng-click="selectPage(page - 1, $event)">{{::getText('previous')}}</a></li> 
    <li ng-repeat="page in pages track by $index" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" class="pagination-page"><a href ng-click="selectPage(page.number, $event)">{{page.text}}</a></li> 
    <li ng-if="::directionLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-next"><a href ng-click="selectPage(page + 1, $event)">{{::getText('next')}}</a></li> 
    <li ng-if="::boundaryLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-last"><a href ng-click="selectPage(totalPages, $event)">{{::getText('last')}}</a></li> 
</ul> 

編輯

由於Shamal指出,ngDisabled是分頁指令範圍:

.directive('pagination', ['$parse', 'paginationConfig', function($parse, paginationConfig) { 
return { 
    restrict: 'EA', 
    scope: { 
     totalItems: '=', 
     firstText: '@', 
     previousText: '@', 
     nextText: '@', 
     lastText: '@', 
     ngDisabled:'=' 
    }, 
... 

回答

1

是ngDisabled是從指示。

如果在指令中將ng-disabled設置爲true,那麼如果noPrevious()返回false,則禁用的類將適用。你可以有條件地將這個類應用於li。

.directive('myDirective', function() { 
    return { 
    restrict: 'E', 
    scope: { 
     ngDisabled: '=' 
    }, 
    templateUrl: 'template.html' 
    }; 
}); 

<my-directive ng-disabled="true"></my-directive> 
+0

我試圖在一個plunker,設置NG-禁用= 「真」,noPrevious()返回的網頁> 1假,但 「上一個」 沒有被禁用。這是你的意思嗎? http://plnkr.co/edit/sN2xLo?p=preview – klode

+0

是的ngDisabled在分頁指令範圍內,你是對的。我之前錯過了。 – klode

+0

嗯,這很奇怪。檢查http://plnkr.co/edit/8TaQkapZRCbD7fYNORKy?p=preview –