角度模板中是否无法在不使用任何html标记的情况下在DOM中重复数组。
//like
<!-- required output -->
<div class="names">
name1 name2 name3 name4
</div>
//expected syntax
<ng-repeat item in items>
{{item.name}}
</ng-repeat>
答案 0 :(得分:0)
我没有使用ng-repeat
而是使用foreach
这是工作code
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.items = ["simon", "joy","dona", "divya"];
$scope.names = function (argument) {
var allNames = "";
angular.forEach($scope.items, function(item) {
allNames = allNames + item + " ";
});
return allNames;
};
});
<body ng-controller="MainCtrl">
<div>{{names()}}</div>
</body>