指令里面没有&LT工作; TR>即NG-重复绑定 [英] directive not working inside <tr> that is ng-repeat bound

查看:137
本文介绍了指令里面没有&LT工作; TR>即NG-重复绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其中的行通过纳克重复重复表。
我想这克里特岛为每一行生成列的模板

 <表>
< TR NG重复=p在位置>
    < customtd位置=P>< / customtd>
< / TR>
< /表>
app.directive(customtd功能(){
返回{
    限制:'E',
    模板:< TD> {{position.Name}}< / TD>< TD> {{位置code}}< / TD>中,
    更换:真实,
    范围: {
      位置:'='
    }
}
});

问题是我的自定义模板,TD不呈现在所有。
在这里,我打算更换< customtd>与LT数为n&; TD> S - 这将根据我的数据对象的属性的数量来决定,而此刻,我只是试图让一个简单的指令工作将输出两列

MYPLUNKER :说明这个问题,并指令code的实例

解决方案

正如评论指出的一个指令的模板应该有一个根元素。因此,我建议你到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆