从$ 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. 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?

问题是进入视图时根本没有删除类,因为我认为我没有正确定位DOM中的元素。你知道我的代码有什么问题吗?

Thanks in advance for your replies!

提前感谢您的回复!

1 个解决方案

#1


1  

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/


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/09/29/f3ce2bb1af6681fae93198e86be3f6b5.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com