ng-include
我观察到,当我在指令中包含一个模板时ng-show
,ng-hide
它似乎不起作用。
注意:在 angularjs1.0.4
和1.0.5
这个作品
template.html
<table ng-init="changeable = null">
<tr ng-repeat="(key, item) in items" ng-click="changeable = key">
<td>
<span ng-show="changeable != key">{{item.name}}</span>
<input ng-hide="changeable != key" ng-model="item.name">
</td>
<td>
<button ng-click="changeable = null">OK</button>
</td>
</tr>
</table>
这不起作用
template.html
<div ng-include src="'/changeable_table.html'"></div>
changeable_table.html
<table ng-init="changeable = null">
<tr ng-repeat="(key, item) in items" ng-click="changeable = key">
<td>
<span ng-show="changeable != key">{{item.name}}</span>
<input ng-hide="changeable != key" ng-model="item.name">
</td>
<td>
<button ng-click="changeable = null">OK</button>
</td>
</tr>
</table>
更新
过了一会儿github@pkozlowski-opensource给我一个 wiki 的链接,它很好地解释了为什么需要这个命名空间,它是作用域原型继承的细微差别