JavaScript How to add a class to an element and remove to the others siblings in AngularJS class element remove,javascript element class remove,js element class

I have a list of li elements which are a sidebar. I'm looking the way to add a class active to the one clicked, and remove that class from the others.

This is my html code:

...
<li ng-click="openNav($event)" ng-class="{'active': isActive }">
    ...
</li>
<li ng-click="openNav($event)" ng-class="{'active': isActive }">
    ...
</li>
<li ng-click="openNav($event)" ng-class="{'active': isActive }">
    ...
</li>

And this is the code on my controller

Test.controller('NavController', function($scope, $http) {
    $scope.isActive = false;

    $scope.openNav = function($event) {
        //$scope.isActive = true;
    }
})

The line $scope.isActive = false; removes the class as I need, but I cannot find the way to add the class to the clicked

Answer:1

This is the angular way to do it...

<li ng-click="openNav(active = 1)" ng-class="{'active': active == 1 }">
<li ng-click="openNav(active = 2)" ng-class="{'active': active == 2 }">
<li ng-click="openNav(active = 3)" ng-class="{'active': active == 3 }">

Edit: Be aware, that you should replace active with something like active.nav so you wont run into issues later.

Answer:2

You can add multiple conditions in ng-class

<li ng-click="openNav($event)" ng-class="{'active': isActive, 'normal': isNotActive }">
Answer:3

I have an array of strings like this values[0]='1,3,16,5,12,43,13'; values[1]='7,1,3,16,5,23,49,26,13'; values[2]='13,1,3,16,5,23,49,26,12'; // etc. on the other hand I have an array filter[0]='13';...

I have an array of strings like this values[0]='1,3,16,5,12,43,13'; values[1]='7,1,3,16,5,23,49,26,13'; values[2]='13,1,3,16,5,23,49,26,12'; // etc. on the other hand I have an array filter[0]='13';...

  1. filter array strings javascript
  2. filter array strings
  3. filter array strings swift
  4. filter array of strings python
  5. filter array of strings java
  6. filter array of strings c#
  7. filter array of strings swift 4
  8. filter array of strings typescript
  9. filter array of strings powershell
  10. angularjs filter array strings
  11. filter array empty strings
  12. filter array of objects strings
  13. lodash filter array of strings
  14. javascript filter array of strings contains
  15. ruby filter array of strings
  16. js filter array of strings
  17. jq filter array of strings
  18. scala filter array of strings
  19. angular filter array of strings
  20. swift filter array of strings case insensitive

Is it possible to use behaviors to share a object between elements? <script> selectedBehavior = { properties: { selected: Object } } </script> <dom-module id="paper-...

Is it possible to use behaviors to share a object between elements? <script> selectedBehavior = { properties: { selected: Object } } </script> <dom-module id="paper-...

I want to load the left half of video texture to left Geometry and right half of video texture to the right Geometry var video = document.createElement("video"); var texture = new THREE.Texture(video)...

I want to load the left half of video texture to left Geometry and right half of video texture to the right Geometry var video = document.createElement("video"); var texture = new THREE.Texture(video)...

  1. three js copy texture

my question is really simple. It is possible use Angular Controllers with prototype? 'use strict'; var EventController = function(scope, EventModel) { this.scope = scope; this....

my question is really simple. It is possible use Angular Controllers with prototype? 'use strict'; var EventController = function(scope, EventModel) { this.scope = scope; this....

  1. in angular controller
  2. angular use controller from another module