我有一个分页链接指令,
app.directive('postsPagination', function(){
return{
restrict: 'E',
template: '<ul class="pagination" ng-show="totalPages > 1">'+
'<li ng-class="disabled: currentPage!=1"><a href="javascript:void(0)" ng-click="getPosts(1)">«</a></li>'+
'<li><a href="javascript:void(0)" ng-click="getPosts(currentPage-1)">‹ Prev</a></li>'+
'<li ng-repeat="i in range" ng-class="{active : currentPage == i}">'+
'<a href="javascript:void(0)" ng-click="getPosts(i)">{{i}}</a>'+
'</li>'+
'<li ng-show="currentPage != totalPages"><a href="javascript:void(0)" ng-click="getPosts(currentPage+1)">Next ›</a></li>'+
'<li ng-show="currentPage != totalPages"><a href="javascript:void(0)" ng-click="getPosts(totalPages)">»</a></li>'+
'</ul>'
};
});
当前页面的值不等于1时,ng-class不起作用。
<li ng-class="disabled: currentPage!=1"><a href="javascript:void(0)" ng-click="getPosts(1)">«</a></li>'+
这是错误。
我该如何解决这个问题?
答案 0 :(得分:1)
尝试将代码包装在{}
中,如:
ng-class="{disabled: currentPage!=1}"