【问题标题】:How to access parent scope in directive on nested ng-repeat如何在嵌套 ng-repeat 的指令中访问父范围
【发布时间】:2017-04-08 19:22:50
【问题描述】:

简单的问题,但我无法在此模板中找到为什么 format-property 指令无法访问设备?

<table>
    <tr ng-repeat="device in devices">
        <format-property ng-repeat="property in properties"></format-property>
    </tr>
</table>

尽管使用此模板它可以工作:

<table>
    <tr ng-repeat="device in devices">
        <td ng-repeat="property in properties">
            <format-property></format-property>
        </td>
    </tr>
</table>

我试过scope.devicescope.$parent.device 没有成功。 这是我的demo

编辑

我可以访问property,但不能访问device。不像this question,我有一个嵌套的ng-repeat

这里是一个新的demo,具有隔离范围

【问题讨论】:

  • 从您的演示中,您似乎正在重新创建一个控制器和一个 $scope 并尝试调用它。您只需传递处理设备和属性 ng-repeats 的控制器。
  • 不,范围是本地范围(ng-repeat的范围)。我可以从指令访问property
  • 第二个工作正常。
  • 是的,但这不是我想要的!
  • 你到底想要什么?

标签: angularjs angularjs-directive


【解决方案1】:

plunker

我认为您必须在tr 中添加td,或者您可以使用div

您也可以查看this 链接了解更多详情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-17
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2015-07-01
    相关资源
    最近更新 更多