在角度模板中重复字符串,不带任何标记

时间:2014-12-03 12:03:29

标签: angularjs angular-directive

角度模板中是否无法在不使用任何html标记的情况下在DOM中重复数组。

//like
<!-- required output -->
<div class="names">
name1 name2 name3 name4
</div>

//expected syntax
<ng-repeat item in items>
{{item.name}}&nbsp;
</ng-repeat>

1 个答案:

答案 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>