带有ng-class的Angular JS指令

时间:2016-11-07 06:36:03

标签: javascript angularjs ng-class

我有一个分页链接指令,

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)">&laquo;</a></li>'+
    '<li><a href="javascript:void(0)" ng-click="getPosts(currentPage-1)">&lsaquo; 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 &rsaquo;</a></li>'+
    '<li ng-show="currentPage != totalPages"><a href="javascript:void(0)" ng-click="getPosts(totalPages)">&raquo;</a></li>'+
  '</ul>'
};
});

当前页面的值不等于1时,ng-class不起作用。

<li ng-class="disabled: currentPage!=1"><a href="javascript:void(0)" ng-click="getPosts(1)">&laquo;</a></li>'+

这是错误。

enter image description here

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试将代码包装在{}中,如:

ng-class="{disabled: currentPage!=1}"