angular.js - ng-repeat 遍历 directive不生效

查看:137
本文介绍了angular.js - ng-repeat 遍历 directive不生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

Demo:http://codepen.io/mafeifan/pe...

ng-repeat 嵌套,先遍历tr再遍历td。
使用原生html能输出正确内容。
但当把td写为directive就不显示了。不知道什么原因,求指教。

解决方案

控制器中增加变量就行:

    vm.list = [1,2];

table2 中修改为:

    <form-cell ng-repeat='cell in vm.list'>data</form-cell>

就可以实现~

ng-repeat 一般不建议 用 动态的,这样 很影响性能。

如果坚持这样写,可以写成:

      <tr ng-repeat="grid in vm.repeatCount() track by $index">
        <td ng-repeat='cell in vm.getDataByIndex($index)'>
          <form-cell></form-cell>
        </td>
      </tr>

值也能过来:

template: '<span>data</span>',

这篇关于angular.js - ng-repeat 遍历 directive不生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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