0
votes

I'm playing with actions in Ember and I see that some people use targets that point to their controllers or their views like such:

{{action saveNote target="view"}

However, I also see that Ember supports event bubbling much like the DOM, in that events will work their way up to the application controller and router.

Is there a reason for specifying either "view" or "controller"? If I understand it correctly, the view/controller that the template's action belongs to will be the first in line to receive the event, so why specify it?

2

2 Answers

3
votes

There's really no reason to target the controller, since it's the default target. Events not handled by the controller will bubble up from the controller to the routes.

However, if you want the view to respond to an action, you'll need to target it explicitly.

3
votes

target="controller' is not needed ( anymore? )

target="view" can have many uses which are perhaps local to a specific view instead of belonging into a controller. Like toggling the display of an item.

But target also has other use cases like if you want to target a controller you have declared in needs which is then accessible in controllers.<nameOfController>