简体   繁体   English

从子应用程序调用父方法

[英]Call parent method from child app

I have checkbox on child app controller, so when user click on it, I need to call some method from parent controller: Parent app controller: 我在子应用程序控制器上具有复选框,因此当用户单击它时,我需要从父控制器调用某些方法:父应用程序控制器:

<div ng-controller="ParentCntr as parentCntr">
    <child-app></child-app>
</div>

Child app: 子应用:

   <div class="child-app" ng-controller="ChildCntr as childCntr">
       <div class="checkbox no-indent">
          <input type="checkbox"
                 name="test"
                 id="test"
                 ng-change="childCntr.DisableText()"
                 ng-model="childCntr.testVar"/>
         <label for="test">Some Text</label>
       </div>
   </div>

So, how to do this in easiest way? 那么,如何以最简单的方式做到这一点?

So to access to the parent scope you can use $parent like this : 因此,要访问父级作用域,您可以像这样使用$ parent:

<div ng-controller='SecondCtrl' ng-click='$parent.testFunction()'>{{$parent.name}}</div>

Here is a working example. 是一个工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM