Подтвердить что ты не робот

Какая альтернатива для jquery каждый в angularjs?

Я хочу удалить jQuery из своего приложения. Но я хочу заменить $.each в angularjs... Как я могу зацикливаться на элементах dom? Здесь я добавил свой код.. Я хочу преобразовать его в 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);
        };
    });
4b9b3361

Ответ 1

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

Вы можете преобразовать его в объект, а затем вы можете использовать его.

Ответ 2

вы можете использовать оператор цикла angular.forEach()

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