Angularjs Foreach loop
Angular has forEach function to loop over a collection. This is demonstrated below.
I am looping over a collection of students. I used angular.forEach function to do so. This function takes two arguments one is the collection or array and the other one is the function which will hold the current item in the collection.
Working demo can be found here
var app=angular.module('app',[]);
app.controller('myCtrl',function($scope){
var students=[
{id:1,name:'Steve',standard:'X'},
{id:2,name:'Richard',standard:'X'},
{id:3,name:'Shawn',standard:'IIX'},
{id:4,name:'Anthony',standard:'IX'}];
angular.forEach(students,function(student){
console.log(student.id,student.name,student.standard);
});
});
I am looping over a collection of students. I used angular.forEach function to do so. This function takes two arguments one is the collection or array and the other one is the function which will hold the current item in the collection.
Working demo can be found here
Comments
Post a Comment