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?
You can send parameters with an action by using sendAction() method which provides additional context to the route or controller to handle an action and has string 'action' as the first argument.
What are the prime tasks that are performed by controllers in Ember. js? Decorating the model which is returned by the route is a very essential task that needs to be performed in Ember.
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
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