ng-repeat没有HTML元素(这次真的没有任何)

Pau*_*aul 5 html repeater angularjs

我希望得到类似的东西:

Line 1<br>
Line 2<br>
Line 3<br>
Line 4<br>
Line 5<br>
Run Code Online (Sandbox Code Playgroud)

使用ng-repeat.除了之外,所有行都应该分开<br>

che*_*tts 3

这是一个硬编码的简单指令<br>

HTML:

<p hidden-repeat="lines"></p>

app.directive('hiddenRepeat',function($parse){
  return {
    link: function(scope, elem, attr){
      var data = $parse(attr.hiddenRepeat)(scope);
      if(data){
        for (var i=0;i< data.length;i++){ 
          elem.append(data[i]+ "<br />");
        }  
      }
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

查看实际效果:http://plnkr.co/edit/Y8eahPYmBr5ohbWCInde ?p=preview

此解决方案允许您在属性中指定指令(在本例中为隐藏重复)。通过使用指令的属性版本,您可以指定包装元素是什么(在本例中为段落)。