Reputation: 3415
I've got two controllers: TaskManageController
and TaskFormController
. The TaskFormController
has function to present it (modally) and the TaskManageController
has an "+" button to add. Currently the TaskManageController
is a parent of the TaskFormController
. How can I call present
on the child controller when clicking the "+" button in the parent controller?
<div ng-controller="TaskManageController AS manage">
...
<a ng-click="manage.add()">+</a>
<div ng-controller="TaskFormController AS form">
...
</div>
</div>
Upvotes: 1
Views: 24
Reputation: 38032
You could use ng-init
to setup a reference to the child controller then use the reference in your manage controller:
<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(); }
}
Upvotes: 1