angular-foreach-3

 

In this example of angular.foreach, there are three parameter in function value, prop and obj. Value contains name value and prop contain property name and obj contains whole object. See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="forEachController"> <p ng-repeat="pr in prop">Properties: {{pr}}</p> <p ng-repeat="vl in val">Value: {{vl}}</p> {{obj}} </div> </body> </html> <script> var app = angular.module("app", []); app.controller('forEachController', ['$scope', function ($scope) { $scope.prop = []; $scope.val = []; $scope.obj = []; angular.forEach({ name: 'Todd', location: 'UK' }, function (value, prop, obj) { $scope.val.push(value); $scope.prop.push(prop); $scope.obj.push(obj); }); }]); </script>
Output