# How can I call an event from my controller to my component

**URL:** <https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228>\
**Category:** Uncategorized\
**Created:** [March 21, 2016, 10:20pm UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228 "2016-03-21T22:20:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubbya](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@dubbya](https://discuss.emberjs.com/u/dubbya)\
**Post date:** [March 21, 2016, 10:20pm UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228/1 "2016-03-21T22:20:53Z")

</div>

Hi All,

Running into an issue that I’ve been stuck on for days and I can’t seem to figure this out. It seems like it would be simple enough but apparently it isn’t. I have an action in my controller:

…controllers/car-detail.js … actions: { callComponent(){ //want to call the fromController() function inside of my component } }

…/components/car-detail.js My Component fromController(){ //something needs to happen in here }

References:

> <https://stackoverflow.com/questions/27802508/ember-js-component-observer-does-not-work>

> <https://stackoverflow.com/questions/19618604/how-to-call-method-of-a-component-from-a-controller>

> <https://stackoverflow.com/questions/22861316/calling-a-controllers-method-in-another-controller-ember>

Can someone lend a hand with this one?

---

<div class="post-metadata">

**Author:** ![vikram7](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/vikram7/32/12393_2.png) [@vikram7](https://discuss.emberjs.com/u/vikram7)\
**Post date:** [March 21, 2016, 10:48pm UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228/2 "2016-03-21T22:48:15Z")

</div>

Why not just handle the action in your component and send it back up to the controller?: [Triggering Changes with Actions - Components - Ember Guides](https://guides.emberjs.com/v2.4.0/components/triggering-changes-with-actions/)

---

<div class="post-metadata">

**Author:** ![dubbya](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@dubbya](https://discuss.emberjs.com/u/dubbya)\
**Post date:** [March 22, 2016, 12:19am UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228/3 "2016-03-22T00:19:43Z")

</div>

Thanks for the response. I’d be ok with that, but the problem is, I need to call a function inside of the component when the component is not actually used, so I can’t really handle the action inside of the component. If i put:

```
actions: {
        callComponent() { 
          //want to call the fromController() function inside of my component 
        }

```

Inside of my component, the callComponent() method will never get fired. The action is being sent by through another controller.

---

<div class="post-metadata">

**Author:** ![gjastrab](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gjastrab/32/14629_2.png) [@gjastrab](https://discuss.emberjs.com/u/gjastrab)\
**Post date:** [March 29, 2016, 4:41am UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228/4 "2016-03-29T04:41:21Z")

</div>

Sounds like you’ll need to use a [service](https://guides.emberjs.com/v2.4.0/applications/services/). The question is does the `fromController()` method need to change something in the display that a computed property on the service could trigger within the component? (For example inject the service into the component and within the component make a computed property off of something within the service. Then the controller action can just grab the service and manipulate it to cause the computed property to change)

If not and you literally just need a method executed within the component then using [Evented - 4.6 - Ember API Documentation](http://emberjs.com/api/classes/Ember.Evented.html) within the service could give you the mechanism you are looking for. So within the controller you could do:

```auto
carThing: Ember.service.inject(),
actions: {
  callComponent() {
    this.get('carThing').triggerEventMethod()
  }
}

```

The car thing service would be something like [this code sample](https://github.com/EmberSherpa/ember-places-autocomplete/blob/solution/addon/services/places-autocomplete.js), extending Evented which would let the `triggerEventMethod()` call `trigger('someEvent')` which the component could be listening for and react to.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![schwaiger](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/schwaiger/32/15769_2.png) [@schwaiger](https://discuss.emberjs.com/u/schwaiger)\
**Post date:** [April 5, 2016, 8:33pm UTC](https://discuss.emberjs.com/t/how-can-i-call-an-event-from-my-controller-to-my-component/10228/5 "2016-04-05T20:33:25Z")

</div>

if you do not need a eventbus in general you can add this to your component

didReceiveAttrs: function() { this.set(‘targetObject.’ + this.get(‘register-as’), this); },

and then you can call your component from controller with prvidet name from register-as attr.

but keep in mind normaly the rule is ddau.
