我有两个控制器:TaskManageController
和TaskFormController
。 TaskFormController
具有呈现它的功能(模态),而TaskManageController
具有" +"按钮添加。目前,TaskManageController
是TaskFormController
的父级。单击" +"时,如何在子控制器上调用present
?父控制器中的按钮?
<div ng-controller="TaskManageController AS manage">
...
<a ng-click="manage.add()">+</a>
<div ng-controller="TaskFormController AS form">
...
</div>
</div>
答案 0 :(得分:1)
您可以使用ng-init
设置对子控制器的引用,然后在管理控制器中使用该引用:
<div ng-controller="TaskManageController AS manage">
...
<a ng-click="manage.add()">+</a>
<div ng-controller="TaskFormController AS form" ng-init="manage.form = form">
...
</div>
</div>
// TaskManageContoller
this.add = function() {
if (this.form) { this.form.present(); }
}