Home > Web Front-end > JS Tutorial > body text

angular.foreach loop method usage guide_AngularJS

WBOY
Release: 2016-05-16 16:21:58
Original
1352 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:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!