Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`$.each()` alternative in Angular JS

What is the alternative for jquery's $.each() loop in Angular JS.

I have got the following in jquery (in my Angular JS based project):

    $($scope.tasks).each(function(index, task){
        if (task.isCompleted) {
            task.showTask = true;
        }
    });

and I don't want to use the mix of jquery and angular, because they say it is a bad practice to do so (is it?). Is there any feature that angular provides like $.each()? Or should I go with the plain javascript?

like image 351
Kamran Ahmed Avatar asked Mar 19 '14 06:03

Kamran Ahmed


1 Answers

You can use angular.forEach() for iterating in angularjs

angular.forEach($scope.tasks, function (task, index) {
    if (task.isCompleted) {
        task.showTask = true;
    }
});
like image 124
Arun P Johny Avatar answered Oct 10 '22 12:10

Arun P Johny