angualarjs

<!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>
相關文章
相關標籤/搜索