NG-重复而不HTML元素(这时候真的没有任何) [英] ng-repeat without HTML element (this time really without any)
本文介绍了NG-重复而不HTML元素(这时候真的没有任何)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想是这样的:
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).
这篇关于NG-重复而不HTML元素(这时候真的没有任何)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文