0

I have a pagination links directive,

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>'
};
});

The ng-class is not working when the value of current page is not equel to 1.

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

This is the error.

enter image description here

How can I solve this issue ?

3
  • is the name of your class is disabled ? what are you trying to achieve ? Commented Nov 7, 2016 at 6:38
  • if currentPage !=1, I want to add class named "disabled" Commented Nov 7, 2016 at 6:38
  • 1
    try wrapping the code in {} like ng-class="{disabled: currentPage!=1}" Commented Nov 7, 2016 at 6:41

1 Answer 1

1

Try wrapping the code in {} like:

ng-class="{disabled: currentPage!=1}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.