Level: Intermediate

Abhilash L R
ember-titbits
2 min readJun 4, 2018

--

Supposing you have an action on your route (say: routes/users.js) and you would like to invoke it from a component rendered on the routes/users.hbs template, how do you do it? There are couple of ways to solve this problem.

1. Use the traditional action=”action” for the component like below:
{{my-component editUser="editUser"}}

And in your my-component.js file, you would be doing this.editUser() which will fire the action on the controller which you will use to send it up to the route.

However, if you are using the new closure syntax as below:

{{my-component editUser=(action "editUser")}}

In this case, Ember complains that there’s no action editUser defined on the controller.

So here come’s the second approach.

2. Bubbling it up with ‘send’ in closure action

{{my-component editUser=(action send 'editUser')}} should do the trick while you have editUser action defined in the parent route. Thanks to Ed for posting this as an answer on StackOverflow.

This was originally posted on StackOverflow at https://stackoverflow.com/a/40043476

PS: Clap if you liked, and don’t forget to follow me here: Abhilash L R or on Twitter @abhilashlr

--

--

Abhilash L R
ember-titbits

Loves to travel, writes about programming, photography, life lessons and sometimes cooking