Is it possible to use ngMousedown for adding class to a div and ngMouseup for removing the class again? At the moment I use ng-mousedown="activateClass()" , in activateClass() change $scope.className="data-active" and change it again with other function with ng-mouseup. And use ng-class to add the class "data-active" I don't wanna use $scope.className and change it with function in controller, because this function is used for several divs and I don't want to add the class to all of the divs I have.
Thank you.
did you mean this:
You can use ng-events with ng-class to achieve it:
Normally controllers should not care about your DOM. What you are trying to do there seems more like suitable for a directive. I would implement a directive:
and use it on a div like this
where as active is the name of my css class.
If you don't want to use controller, you may just write ng-mousedown="className='data-active'" in your view