什么是angularjs替代jQuery的每一个? [英] What is the alternative for jquery each in angularjs?
本文介绍了什么是angularjs替代jQuery的每一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的应用程序中删除jQuery的..但我想为$。每次在angularjs替代...
我怎么能环周围的DOM元素?
在这里,我已经加入我的code ..我想将其转换成angularjs从jQuery的
app.directive('activeu',函数($位置){
返回函数($范围,元素,ATTRS){
VAR menuMain = $ $范围parent.menuMain。
。VAR完整路径= $ location.path()分('/');
无功电流=完整路径[2]; 的setTimeout(函数(){
$(NAV李一)。每个(函数(){
如果($(本).attr('HREF')=='#!/页/+电流){
$(本).parent()addClass(激活)。
$(本).closest('li.root礼')addClass(激活)。 如果($(本).closest('li.parent')长度的方式> 0){
$(本).closest('li.parent')addClass(激活)。
}
}
}); $(NAV李一)。在('点击',功能(){
当前= $(本).attr('href属性);
$(#页菜单的.navigation丽)。每个(函数(){
如果($(本).hasClass(激活)){
$(本).removeClass(激活);
}
}); $(NAV李一)。每个(函数(){
如果($(本).attr('href属性)==电流){
$(本).parent()addClass(激活)。
$(本).closest('li.root礼')addClass(激活)。 如果($(本).closest('li.parent')长度的方式> 0){
$(本).closest('li.parent')addClass(激活)。
}
}
});
});
},500);
};
});
解决方案
angular.forEach(angular.element(李一),功能(值,键){
VAR一个= angular.element(值);
a.addClass(SS);
});
您可以将其转换为对象,然后,你可以使用它。
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屋!
查看全文