How to specify a component action target to a route?


#1

Suppose I have a component called ‘play-music’, and it has a action called ‘play’, what could I do to specify the action target to a route, but not the controller.
I tried play=(action 'play' target="route:someRouteName"), but I had a error said can not find action of undefined.
please help me .


#2

In your case, you’ll want to go the sendAction route instead of passing the action around as a closure, which in that case is the target. Using sendAction will allow the action the bubble in the way you’re expecting. component -> controller -> route

http://guides.emberjs.com/v1.13.0/templates/actions/#toc_the-code-action-code-helper


#3

I just ran into this problem a moment ago- except I was trying to invoke the action on the route of the template the component was used in- by doing the following:

//foo/template.hbs
{{my-component onSave='handleSave`}}

//foo/route.js
actions: {
  handleSave() { ... }
}

//my-component/component.js
this.sendAction( 'onSave' );

I’m unsure why when passing the action as a closure it bubbles up to the controller and not the route. Perhaps once they do away with controllers and have routable components it would simply then bubble up to the route?


#4

Is there a solution to closure actions from a route assigned to a component?