24
votes

I have defined two custom objects, whereby the first one is extending Ember.TextField and the second one Ember.Select. When the appropriate action is trigger in Ember.TextField I do some processing and if a requirement is satisfied then I propagate the action to the underlying controller using @sendAction("actionName").

However, when I try to do the same using Ember.Select I get the following Error:

Uncaught TypeError: Object [object Object] has no method 'sendAction' 

and have to use @get("controller").send("actionName") instead. My mentor reckons that this inconsistency leads to spaghetti code and I do agree with him. Why can't I call @sendAction from Ember.Select, which is a preferred way I've come to understand, in Ember?

What is the main difference between the two?

1

1 Answers

18
votes

sendAction should be used when inside a component. It allows you to breach the confines of a component, if that action is defined when hooking up the component. This helps keep maintain the isolation guaranteed by components, but still allows the component to send messages if you want to listen to it. https://guides.emberjs.com/v2.4.0/components/triggering-changes-with-actions/

{{my-component someInternalAction=someExternalAction}}

send should be used everywhere else.

Ember.Select and Ember.TextField are both components, hence you need to use sendAction