EmberJS: how to handle actions from a view, not a route / controller

Today I came to a shocking discovery: the actions specified in the view are processed according to their route, and not according to the form to which it refers. Example:

<a href="#" {{action edit}}>Edit this</a> 

The edit action must be defined in the Route, not in the view. When I did not use the router before View was responsible for handling such events, and I was very happy about it.

Can anyone:

  • explain to me why the route should handle the event, and what are the benefits of this
  • tell me, how can I gain control over the View in the handling of such actions / events?
+4
source share
1 answer

Set a goal as a view

 <a href="#" {{action edit target="view"}}>Edit this</a> 

If your action is in the controller, use

 <a href="#" {{action edit}}>Edit this</a> 

Target defaults to view controller

I suggest you go through this link: Ember Action Helper

I would like to mention some key points in accordance with the link above

In a typical Ember.Router-backed application, where views are managed using the {{outlet}} helper, actions will be redirected to the current controller.

If the action is not defined in the controller, then the current route is targeted.
+16
source

Source: https://habr.com/ru/post/1443447/


All Articles