hoo*_*ogw 0 angularjs angularjs-directive
<div ng-controller="xxxController" >
<table>
<tr ng-repeat="x in xxxx">
<td>...
</td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
ng-controller标签在任何表格旁边,它工作正常.
但是如果ng-contoller标签在任何表格内,则ng-repeat不起作用
<table>
<div ng-controller="xxxController" >
<tr ng-repeat="x in xxxx">
<td>...
</td>
</tr>
</div>
</table>
Run Code Online (Sandbox Code Playgroud)
<div>
不是有效的子元素<table>
.因此,它<div ng-controller="xxxController">
会被移到外面<table>
,使得<tr>
无效,因为它们也会在外面<table>
.
为了让a <div>
在里面,<table>
它实际上需要是a的孩子<td>
,我认为这会破坏你的结构.
作为替代方案,ng-controller
在<table>
元素本身上使用它是一种有效的语法:
<table ng-controller="xxxController">
<tr ng-repeat'"x in xxx">
<td>...
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)