【发布时间】:2013-09-27 16:47:44
【问题描述】:
我有一个在表中创建一行的指令。然后我使用 ng-repeat 遍历项目列表以使用指令行填充表,例如:
<tr ng-repeat='item in items' rowItem='item' />
我在定义范围时遇到问题。
我不能使用scope: false,因为它不会分隔 rowItem 值。
我希望能够绑定到 rowItem 值,因此使用隔离范围:scope:{rowItem: '='} 可以按我的意愿工作,但我仍然希望可以访问父范围值。
所以最好的选择是scope: true 但是,我无法将范围绑定到行项目。
我尝试使用attrs.$observe('rowItem', ...),但是当项目列表更改时不会触发,因为 rowItem 不是插值属性。
有没有办法使用可以绑定到属性的新子范围 (scope: true)(就像在隔离范围中一样)?
【问题讨论】:
-
You observer like this scope.watch(attrs.rowItem,function) -
谢谢,我已经尝试过了,但它的工作原理与 attrs.$observe 相同,并且仅在属性值更改而不是插值更改时更新。
标签: angularjs scope angularjs-directive