我不确定这是否真的可能,但我本质上想要一个AngularJS中的'&‘隔离作用域的反向。这是一个演示的Plunkr。
基本上,我有一个自定义指令设置,它提供一些可重用的HTML。它使用ng-transclude
来允许在其中呈现一些外部内容。但是,我发现有一种情况是,我想从代码的转换部分访问在指令的isolate作用域上设置的函数。
所以基本上我有一些东西看起来像这样:
<div ng-controller="MainController">
<!-- The directive -->
<div some-custom-directive>
<!-- Button 1 that invokes a method within the controller scope -->
<button id="button1" ng-click="invoke1()">Invoke from Controller</button>
<!-- Button 2 that invokes a method on the isolate scope for the custom directive -->
<button id="button2" ng-click="invoke2()">Invoke from Isolate Scope</button>
</div>
</div>
有没有人知道这是否真的可能?
更新
根据@Mark Rajcok的回答,在$scope
上找到的$$prevSibling
可用于从转换的内容中访问指令的隔离作用域。但是,我已经更新了上面的Plunkr,以尝试从ng-repeat
指令中执行此操作,但这并不起作用。我假设repeat中的项不继承作用域。
https://stackoverflow.com/questions/16171952
复制相似问题