從$ 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