Answer the question
In order to leave comments, you need to log in
Directive execution?
There is a directive that switches the class:
myApp.directive('toggleClass', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
element.toggleClass(attrs.toggleClass);
});
}
};
});
<div class="hide-elements"></div>
<button class="add">+</button>
Answer the question
In order to leave comments, you need to log in
use ng-click and state binding, don't work with the DOM yourself.
The whole point of angular is in the declarative view, that is, no attempts to change something in the DOM on their own.
<div class="hide-elements" ng-class="{'your-class-name': vm.some.condition}"></div>
<button class="add" ng-click="vm.add()">+</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question