luke77
luke77

Reputation: 232

EMBERJS : How to trigger an action in a child component?

I know the concept of Data Down / Actions Up, but I'm facing a situation on which I don't know how to do it with the DDAU. I searched on differents forum and blogs how to do it, but it does not fit my request.

I have a controller with two components. On the first component I have a header with a button. On the second component I have a form.

When the button is clicked, an action is trigered and catched by the controller, but how can I notify the second component of the "click" on the button on the first component.

An easy solution would have been to include the first component in the second one, but I can't do this because each component are used in many different situations.

Upvotes: 2

Views: 3705

Answers (2)

Ebrahim Pasbani
Ebrahim Pasbani

Reputation: 9396

You can use services as a bus.

Register an event on second component and trigger that event from first component.

I show it in this twiddle

If you don't want using services you can use parent-child model.

Please take a look at that twiddle

Upvotes: 3

Ember Freak
Ember Freak

Reputation: 12872

You can pass foo property from controller to both components, and first component to pass action to controller to change foo. Now this sibling component too will be notified and you can make use of didUpdateAttrs hook in sibling component to react to change.

Upvotes: 0

Related Questions