L
L
lohmag2017-01-28 21:00:02
Angular
lohmag, 2017-01-28 21:00:02

How to remove a class from neighboring elements on an event?

How in Angular 1, when clicking on different elements, not only assign them a class, but at the same time remove it from all neighboring elements? In this example it is "flag-active-page"
Here is the css:

<div class="pagination">
        <ul>
          <li><a class="page" ng-click="toPage(1)" href="#">1</a></li>
          <li><a class="page flag-active-page" ng-click="toPage(2)" href="#">2</a></li>
          <li><a class="page" ng-click="toPage(3)" href="#">3</a></li>
          <li><a class="page" ng-click="toPage(4)" href="#">4</a></li>
          <li><a class="page" ng-click="toPage(5)" href="#">5</a></li>
          <li><a class="page-next" ng-click="nextPage()" href="#">...</a></li>
          <li><a class="page" ng-click="toPage(numPages())" href="#">{{numPages()}}</a></li>
        </ul>
      </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2017-01-31
@healqq

Well, only if ng-class is used like this:

function isActivePage(index) {
    return (vm.index === index);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question