<!DOCTYPE html>
<html ng-app="test">
<head>
<title>angularJs-forEach</title>
</head>
<body>
<div ng-controller="ForEachCtrl">{{text}}</div>
<script type="text/javascript" src="../js/angular.min.js"></script>
<script type="text/javascript">
var test = angular.module('test', []);
test.controller('ForEachCtrl', function($scope){
var arr = ['A', 'B', 'C'],
text = [];
angular.forEach(arr, function(value, key) {
this.push(key+ ":" + value);
}, text);
$scope.text = text.join(' ')
})
</script>
</body>
</html>
转载于:https://my.oschina.net/u/2395167/blog/471996