1

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>

1 Answer 1

1

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(); }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.