d_z90 d_z90 - 1 year ago 58
AngularJS Question

Remove class from all angular elements with specific attributes on $ionicView.enter

I am creating a project in

where when entering a particular view, a
from all the elements with some specific attributes, should be removed. This is my chunk of code:

$scope.$on('$ionicView.beforeEnter', function() {

The issue is that the class is not removed at all when entering the view, since I think I am not target correctly the elements in the DOM. Do you have an idea what is the issue with my code?

Thanks in advance for your replies!

Answer Source

Try this:

$scope.$on('$ionicView.beforeEnter', function() {
       var elements = document.querySelectorAll('i.icon.ion-android-favorite');
       for (var i = 0; i < itens.length; i++){
           elements[i].className = elements[i].className.replace("icon-love", "");

To clarify follow this example: https://jsfiddle.net/lucassilvax/9b4pzszm/