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