【发布时间】:2017-01-04 01:52:15
【问题描述】:
这里是演示:http://codepen.io/mafeifan/pen/PzrGRE?editors=1010
table1 正在工作,
在 table2 我写了一个指令来渲染 td ,但不起作用。我不知道为什么。
HTML:
<table>
<tbody>
<tr ng-repeat="tr in vm.getTrs() track by $index">
<form-cell ng-repeat="cell in vm.getCellsByRow($index+1)">data</form-cell>
</tr>
</tbody>
</table>
JS:
App.directive('formCell', function(){
return {
replace: true,
template: '<td>td</td>'
}
});
如果我改成
<table>
<tbody>
<tr ng-repeat="tr in vm.getTrs() track by $index">
<td ng-repeat="cell in vm.getCellsByRow($index+1)"><form-cell></form-cell></td>
</tr>
</tbody>
</table>
JS:
change the template to '<span>td</td>' in directive
它工作正常,我不知道为什么
【问题讨论】:
-
form-cell不是有效的 html 标记。你也需要td或th在tr
标签: javascript angularjs angularjs-directive