Hello everyone, I am going to share the for each loop in angularjs, The angularjs provide the syntax angular.forEach() for handle the iterations. i.e.
Click for Live plnker demo.
Click for Live plnker demo.
1
2
3
4
| //how to use the angular.forEach() in angularjs? angular.forEach(Items, function (index) { console.log(index.Key+ ' ' + index.val); }); |
//how to use the angular.forEach() in angularjs? angular.forEach(Items, function(index) { console.log(index.Key+ ' ' + index.val); });
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
| //The angularJs code-sample as given below. var app = angular.module( "foreachApp" , []); app.controller( "TodoForEach" , function ($scope) { $scope.userDetails = [{ name: 'Anil Singh' , age: 30 }, { name: 'Reena Singh' , age: 25 }]; //This is the foreach loop as given below. $scope.foreachInAngularJs = function () { app.forEach($scope.userDetails, function (val) { console.log(val.name + ' ' + val.age); }); }; } |
//The angularJs code-sample as given below. var app = angular.module("foreachApp", []); app.controller("TodoForEach", function($scope) { $scope.userDetails = [{ name: 'Anil Singh', age: 30 }, { name: 'Reena Singh', age: 25 }]; //This is the foreach loop as given below. $scope.foreachInAngularJs = function() { app.forEach($scope.userDetails, function(val) { console.log(val.name + ' ' + val.age); }); }; }The full demo code-sample.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| //The AngularJs live demo example as given below. <!doctype html> <html> <head> <title>foreach in angularjs mvc 5</title> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js" ></script> <script> var app = angular.module( "foreachApp" , []); app.controller( "TodoForEach" , function ($scope) { $scope.userDetails = [{ name: 'Anil Singh' , age: 30 }, { name: 'Reena Singh' , age: 25 }]; //This is foreach loop. $scope.foreachInAngularJs = function () { app.forEach($scope.userDetails, function (val) { console.log(val.name + ' ' + val.age); }); }; } </script> </head> <body ng-app= "foreachApp" > <div ng-controller= "TodoForEach" > <div>TODO: code-sample.com</div> </div> </body> </html> |
//The AngularJs live demo example as given below. <!doctype html> <html> <head> <title>foreach in angularjs mvc 5</title> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script> <script> var app = angular.module("foreachApp", []); app.controller("TodoForEach", function($scope) { $scope.userDetails = [{ name: 'Anil Singh', age: 30 }, { name: 'Reena Singh', age: 25 }]; //This is foreach loop. $scope.foreachInAngularJs = function() { app.forEach($scope.userDetails, function(val) { console.log(val.name + ' ' + val.age); }); }; } </script> </head> <body ng-app="foreachApp"> <div ng-controller="TodoForEach"> <div>TODO: code-sample.com</div> </div> </body> </html>