AngularJS ForEach Function – Angular Foreach Examples

AngularJS ForEach Function – Angular Foreach Examples

1.object: Object to iterate over.The simple object interate over.
2.iterator: Iterator function.The simple iterator function or the code.
3.context: Object to become context data (using this keywords) for the iterator function.

angular.forEach – function in module ng (using Angularjs)

forEach() Syntax

angular.forEach(object, iterator, [context])

Iterate or Loop(Angularjs ForEach loop) Through Each Item al the data in An Array or Object in AngularJS“AngularJS ForEach Function – Angular Foreach Examples”

AngularJS forEach() Function Example

angular.forEach($scope.dataSource, function (item,index) {
	$scope.stringval_sub = item['fagkode'];
});

AngularJs Break Foreach Loop | angular foreach index | angular foreach example

var index = -1;		
var comArr = eval( $scope.subject_result );
for( var i = 0; i < comArr.length; i++ ) {
	if( comArr[i].sub_id === stid ) {
		index = i;
		$scope.subject_result[i].isdeleted = 1;
		break;
	}
}
if( index === -1 ) {
	
}
$scope.subject_result;

angular.foreach Examples – infinityknow.com

for (var i = 0; i <  $scope.resultdata.length; i++) {
  if ( $scope.resultdata[i][1] == idx+1) {
	 $scope.resultdata.splice(i, 1);
	 $scope.count1 = $scope.resultdata.length;
  }
}

Using Angular forEach() with an Object Example

<div>
    <div>
        Total rate: {{result}}
    </div>
</div>

    var obj = [{
        "item" : "infinityknow",
        "rate" : 50
    },
    {
        "item" : "tutorials",
        "rate" : 25
    }];
    angular.module("infinityApp", [])
        .controller("liveCtrl", function($scope){
            $scope.result = 0;
            angular.forEach(obj, function(value, key){
                $scope.result += value.rate;
            });
        });

angular foreach Value and Key Example

var posts = {name: 'infinityknow', gender: 'male'};
var log = [];
angular.forEach(posts, function(value, key) {
  this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: infinityknow', 'gender: male']);

Example

READ :  Angularjs Multiple Image Slider - Thumbnails Slider Example

Leave a Reply

Your email address will not be published. Required fields are marked *