How to pass strings from a component to its parent handlebar or controller

I want to pass some values from my component to its parent controller or to its parent handlebar. How can i do this??

Hi @sarangsbabu, welcome! The short answer is that, in the vast majority of cases, the parent controller or component should “own” the data and pass it into the component, not vice versa. Ember convention is what we call “data down actions up” meaning you pass data down the component hierarchy and fire actions up the component hierarchy. Typically when you run into a scenario where a child has something the parent doesn’t but you want the parent to have it, it means you should make the parent the data owner instead. There’s a lot of nuance to this in practice, and there are a lot of component design principles which I think come into play, so there’s not an easy prescription.

Anyway I don’t have any context for your particular situation but you have a couple options:

  1. “hoist” the data up the component hierarchy so the parent component (or controller in this case) “owns” the data
  2. fire an action up the hierarchy with some data in it
  3. Use a service. I only recommend this as something you could do, not necessarily as something you should do. This sounds like a component design problem to me so I would only use services in fairly exceptional cases.
3 Likes