2017-08-10 139 views
0

我有孩子的应用程序控制器上复选框,所以当它的用户点击,我需要调用从父控制器的一些方法: 父应用程序控制器:调用父类的方法

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

儿童应用:

<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> 

那么,如何以最简单的方式做到这一点?

+2

尝试'$ parent.yourFunction()' – JeanJacques

+4

ng-click =“parentCntr.myMethod()”? –

+1

[AngularJS从子控制器访问父范围]的可能副本(https://stackoverflow.com/questions/21453697/angularjs-access-parent-scope-from-child-controller) – Vivz

回答

0

因此,要访问父范围可以使用$父这样的:

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

Here是一个工作的例子。