2013-07-09 7 views
25

मैं अपने ऐप से jquery को हटाना चाहता हूं .. लेकिन मुझे angularjs में $ .each के लिए विकल्प चाहिए ... मैं डोम तत्वों के चारों ओर कैसे लूप कर सकता हूं ?? यहाँ मैं अपने कोड को शामिल किया है .. मैंangularjs में प्रत्येक 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); 
     }; 
    }); 

उत्तर

64
angular.forEach(angular.element("li a"), function(value, key){ 
    var a = angular.element(value); 
    a.addClass('ss'); 
}); 

उपयोग कर सकते हैं इसके बाद आप वस्तु में परिवर्तित कर सकते हैं और jQuery से AngularJS में परिवर्तित करना चाहते हैं , आप इसका उपयोग कर सकते हैं ..

13

आप पाश बयान angular.forEach()

var values = {name: 'misko', gender: 'male'}; 
angular.forEach(values, function(value, key){ 
    console.log(key + ': ' + value); 
}); 
+0

यह मुझे var htm = "Login" जैसा दे रहा है .. मैं इसे htm.href की तरह एक्सेस कर सकता हूं .. लेकिन इसके बजाय अगर मैं इसे htm.attr ('href') की तरह एक्सेस करना चाहता हूं, किस तरह क्या इसे मै कर सकता हूँ?? – Amb

+0

@amss मुझे लगता है कि आपको कुछ और विवरण साझा करने की आवश्यकता है कि आप किस प्रकार का डेटा पुन: प्रयास करने की कोशिश कर रहे हैं और वांछित आउटपुट –

+0

मैंने अपना प्रश्न संपादित किया है ... मैं प्रत्येक को jquery को कोणीय में बदलना चाहता हूं। इसके लिए – Amb

संबंधित मुद्दे