首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Access指令的隔离作用域来自transcluded内容

Access指令的隔离作用域来自transcluded内容
EN

Stack Overflow用户
提问于 2013-04-23 22:28:00
回答 3查看 6.4K关注 0票数 16

我不确定这是否真的可能,但我本质上想要一个AngularJS中的'&‘隔离作用域的反向。这是一个演示的Plunkr

基本上,我有一个自定义指令设置,它提供一些可重用的HTML。它使用ng-transclude来允许在其中呈现一些外部内容。但是,我发现有一种情况是,我想从代码的转换部分访问在指令的isolate作用域上设置的函数。

所以基本上我有一些东西看起来像这样:

代码语言:javascript
运行
复制
<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中的项不继承作用域。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16171952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档