0

i am doing a pagination, now i have to do that, if i am currently on page my button must change color.

I have done so far:

<span ng-repeat="page in pagination(pages) track by $index">
  <button ng-class="{ changecolour: isActive(page) }" ng-click='loadProducts($index+1, pageSize)' class="btn btn-default">{{$index+1}}</button>
</span>

controller

$scope.isActive = function (page) {
  return page == page;
};

I know that it is wrong, can someone tell me how to do that??

1

2 Answers 2

0

You need to set the $scope.page value inside the function loadProducts($index+1, pageSize) whenever you click the button. Let's say your function be like this

$scope.loadProducts = function(index, pageSize){
    //determine the page 
    $scope.page = index;
}

And use ng-class as

ng-class="{ changecolour: isActive($index+1) }"

Now your isActive function will be

$scope.isActive = function(page){
   return $scope.page === page;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can Do like this If you have page = page number.

ng-class="{active: page == currentPage}"

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.