foreach in angularjs mvc 5

foreach in angularjs mvc 5

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.

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>
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

foreach in angularjs mvc 5 foreach in angularjs mvc 5 Reviewed by Anil Singh on 8:34 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^