forEach in angularJS
forEach is iterator of object collection convert to collection of array. An array into collection of iterator have two param value and key.
Value - a value of properties in a iterator collection.
key - properties of value
Syntax :
angular.forEach(obj, iterator, [context])
Example :
<div ng-app="modeleach">
<div ng-controller="controllereach">
For each array value {{temp}}
</div>
</div>
JavaScript :
var app = angular.module("modeleach",[]);
app.controller("controllereach",['$scope',function($scope){
var techArray = {name:"rajesh", state:"tamilnadu", country:"india" };
var val = [];
angular.forEach(techArray, function(value, key) {
this.push(value);
}, val);
console.log("List of item ==> "+ val);
$scope.temp = val;
}]);
Comments
Post a Comment