NG-重复而不HTML元素(这时候真的没有任何)没有任何、而不、这时候、元素

由网友(像风活自由)分享简介:我想是这样的:Line 1Line 2Line 3Line 4Line 5采用NG-重复。线应该没有什么,除了分隔< BR> 推荐答案下面是一个简单的指令,C $ CS的&LT硬件$; BR> Here is a simplistic dir...

我想是这样的:

Line 1<br>
Line 2<br>
Line 3<br>
Line 4<br>
Line 5<br>

采用NG-重复。线应该没有什么,除了分隔&LT; BR&GT;

推荐答案

下面是一个简单的指令,C $ CS的&LT硬件$; BR&GT;

Here is a simplistic directive that hard-codes the <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 />");
        }  
      }
    }
  };
});

看到它在行动: http://plnkr.co/edit/Y8eahPYmBr5ohbWCInde? p = preVIEW

这个解决方案允许您指定属性的指令(在这种情况下,隐藏重复)。通过使用一个指令的属性的版本,可以指定缠绕元件是什么(在这种情况下,一个段)。

This solution allows you to specify the directive in an attribute (In this case, hidden-repeat). By using the attribute version of a directive, you can specify what the wrapping element is (In this case, a paragraph).

阅读全文

相关推荐

最新文章