AngularJs Learning Note 4 foreach

Source: Internet
Author: User

Foreach

The angular has its own life cycle. Loop to a angular listener when the variable value is complex. It is best to use angular's own loop method . "Angular.foreach"

Format:


var objs =[{a:1},{a:2}];
Angular.foreach (OBJS, function (Data,index,array) {
Data equivalent to Array[index]
Console.log (data.a+ ' = ' +array[index].a);
});

The parameters are as follows:

OBJS: The collection that needs to be traversed

Data: Time Elapsed for current

Index: Elapsed Current Index

Array: A collection that needs to be traversed, each time it is traversed, the OBJS is passed as-is.

Or

var objs =[{a:1},{a:2}];
Angular.foreach (OBJS, function (data) {
Console.log (DATA.A);
});

Talk about the stupid experience ==!

Defining variables with problems and not knowing ... After the value, assignment, how all have problems.

The previous definition

Vm.coder.codeAry =new Array (), subsequent assignment Angular.foreach (vm.codera.res_alloc_code,function (data,index,array) {                            if ( Array[index].code = = Vm.codeid) {                                vm.codera.codeAry.push (data);//push does not go in                                console.log (vm.codera.codeAry);                                Vm.codera.codeAry.codeTemp = data;//This step is a natural error                            }                    )

  

Push does not go into an array, define Vm.codera.codeAry =[], and then directly use for, copy to ... Still hold the wrong   back to see, the original Vm.codera no such data ... Why don't I take a look at the error, ==!?

Right Code:

AngularJs Learning Note 4 foreach

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.