简体   繁体   English

从$ ionicView.enter上具有特定属性的所有角度元素中删除类

[英]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. 我正在用ionic创建一个项目,当进入特定视图时,应删除所有具有某些特定属性的元素中的class 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. 问题是进入视图时根本不会删除该类,因为我认为我没有正确地将DOM中的元素作为目标。 Do you have an idea what is the issue with my code? 您知道我的代码有什么问题吗?

Thanks in advance for your replies! 提前感谢您的回复!

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/ 为了澄清,请遵循以下示例: https : //jsfiddle.net/lucassilvax/9b4pzszm/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM