d_z90 d_z90 - 2 months ago 6
AngularJS Question

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

I am creating a project in

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

$scope.$on('$ionicView.beforeEnter', function() {
angular.element(document.querySelectorAll('i.icon.ion-android-favorite'))
.removeClass('icon-love');
});


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

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/

Comments