search

Home  >  Q&A  >  body text

angular.js - ng-repeat traversal directive does not take effect

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

ng-repeat is nested, traversing tr first and then td.
Using native html can output correct content.
But when td is written as directive, it will not be displayed. I don't know why, please give me some advice.

PHPzPHPz2808 days ago643

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-15 17:07:53

    Just add variables in the controller:

        vm.list = [1,2];

    table2 is modified to:

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

    It can be achieved~

    ng-repeat is generally not recommended to be dynamic, as this will affect performance.

    If you insist on writing like this, you can write it as:

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

    The value can also come:

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

    reply
    0
  • Cancelreply