Home > Web Front-end > JS Tutorial > angular.foreach loop method usage guide_AngularJS

angular.foreach loop method usage guide_AngularJS

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:21:58
Original
1458 people have browsed it

angular has its own life cycle. When looping to a variable monitored by angular. It is best to use the loop method that comes with Angular. "angular.foreach"

Format:

Copy code The code is as follows:

var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data,index,array){
//data is equivalent to array[index]
console.log(data.a '=' array[index].a);
});

The parameters are as follows:

objs: Collection that needs to be traversed

data: current data during traversal

index: current index when traversing

array: The collection that needs to be traversed, objs will be passed as it is every time it is traversed.

You don’t need to write the last two parameters:

Copy code The code is as follows:

var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data){
console.log(data.a);
});
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
angular.js - angularJS ng-style用法
From 1970-01-01 08:00:00
0
0
0
angular.js - AngularJS form validation
From 1970-01-01 08:00:00
0
0
0
angular.js - Learning AngularJS
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template