angularjs 中每个 jquery 的替代方法是什么? [英] What is the alternative for jquery each in angularjs?
本文介绍了angularjs 中每个 jquery 的替代方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的应用程序中删除 jquery .. 但我想在 angularjs 中替换 $.each ......如何循环 dom 元素?在这里我添加了我的代码..我想将它从 jquery 转换成 angularjs
I want to remove jquery from my app.. But I want substitute for $.each in angularjs... How can I loop around dom elements ?? Here I have added my code.. I want to convert it into angularjs from jquery
app.directive('activeu', function($location) {
return function ($scope, element, attrs) {
var menuMain = $scope.$parent.menuMain;
var fullpath = $location.path().split('/');
var current = fullpath[2];
setTimeout(function() {
$(".nav li a").each(function() {
if ($(this).attr('href') == '#!/page/' + current) {
$(this).parent().addClass('active');
$(this).closest('li.root-li').addClass('active');
if ($(this).closest('li.parent').length > 0) {
$(this).closest('li.parent').addClass('active');
}
}
});
$(".nav li a").on('click', function() {
current = $(this).attr('href');
$("#pages-menu .navigation li").each(function() {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
});
$(".nav li a").each(function() {
if ($(this).attr('href') == current) {
$(this).parent().addClass('active');
$(this).closest('li.root-li').addClass('active');
if ($(this).closest('li.parent').length > 0) {
$(this).closest('li.parent').addClass('active');
}
}
});
});
}, 500);
};
});
推荐答案
angular.forEach(angular.element("li a"), function(value, key){
var a = angular.element(value);
a.addClass('ss');
});
你可以把它转换成对象,然后你就可以使用它了..
You can convert it into object and then, you can use it..
这篇关于angularjs 中每个 jquery 的替代方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文