I have an action that may be triggered from different routes/templates, but ultimately should be sent to an action in the application controller. How do I do this? I've only seen examples of the needs
property being used for sending actions to child controllers.
So how can actions sent from /posts/post
and /
(application) both be sent to the application controller?
You usually define the action handler in the ApplicationRoute as:
App.ApplicationRoute = Em.Route.extend({
actions: {
print: function() {
console.log('hello');
}
}
});
Then, if your action is not defined either on your controller or specific route, the action will bubble up to any parent routes until the ApplicationRoute.
If you want to handle the action in your route and at the application level, you must return true in your action handler in order the action can bubble up.
App.IndexRoute = Em.Route.extend({
actions: {
print: function() {
console.log('hello');
return true;
}
}
});
Check the guide for a detailed description.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With