指令里面没有&LT工作; TR&GT;即NG-重复绑定 [英] directive not working inside <tr> that is ng-repeat bound
问题描述
我有其中的行通过纳克重复重复表。
我想这克里特岛为每一行生成列的模板
&LT;表&gt;
&LT; TR NG重复=p在位置&GT;
&LT; customtd位置=P&GT;&LT; / customtd&GT;
&LT; / TR&GT;
&LT; /表&gt;
app.directive(customtd功能(){
返回{
限制:'E',
模板:&LT; TD&GT; {{position.Name}}&LT; / TD&GT;&LT; TD&GT; {{位置code}}&LT; / TD&gt;中,
更换:真实,
范围: {
位置:'='
}
}
});
问题是我的自定义模板,TD不呈现在所有。
在这里,我打算更换&LT; customtd&GT;与LT数为n&; TD&GT; S - 这将根据我的数据对象的属性的数量来决定,而此刻,我只是试图让一个简单的指令工作将输出两列
MYPLUNKER :说明这个问题,并指令code的实例。 p>
正如评论指出的一个指令的模板应该有一个根元素。因此,我建议你到 TR
元素移动到该指令的模板,这样的:<一href=\"http://plnkr.co/edit/YjLEDSGVipuKTqC2i4Ng?p=$p$pview\">http://plnkr.co/edit/YjLEDSGVipuKTqC2i4Ng?p=$p$pview
I have a table where the rows are repeated via ng-repeat. I am trying to crete a template that generates columns for each row
<table>
<tr ng-repeat="p in positions">
<customtd position="p"></customtd>
</tr>
</table>
app.directive("customtd", function(){
return {
restrict: 'E',
template: "<td>{{position.Name}}</td><td>{{position.Code}}</td>",
replace: true,
scope: {
position: '='
}
}
});
The issue is my custom td template is not rendered at all. Here I intend to replace <customtd> with n number of <td>s - which will be decided based on number of properties on my data object, but at the moment I am just trying to get a simple directive working that will output two columns.
MYPLUNKER : shows an instance of this issue and the directive code.
As pointed out in comments the template of a directive should have single root element. So I would suggest you to move the tr
element to the template of the directive, like this: http://plnkr.co/edit/YjLEDSGVipuKTqC2i4Ng?p=preview
这篇关于指令里面没有&LT工作; TR&GT;即NG-重复绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!