Angular 带有 ng-class 的 JS 指令

Angular JS Directive with 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>'+

这是错误。

我该如何解决这个问题?

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

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