Send() undefined for nested routes

I’m trying access the action from the parent controller in the child controller. The following error occurs : Uncaught TypeError: Cannot read property ‘send’ of undefined. How to use the parent controller’s action in child controller ?

Parent Hbs :

Parent Controller : Child Hbs : Child controller:

Hey, Best idea would be to extract message action to mixin and extend both controllers with it.

1 Like

Thanks for your reply! But I’m pretty new to ember and I have not used mixins here.

No problem, you can learn about mixins here Mixin - 4.6 - Ember API Documentation

So I believe the needs syntax is no longer a thing, and if it was you’d want the “needs” at the root level of the controller anyway, not in the actions hash. If you want to do something like this in modern Ember I believe you can do the following:

import Controller, {
  inject as controller
} from '@ember/controller';

export default Controller.extend({
  parent: controller(),

  actions: {
    message() {
      this.get('parent').send('message');
    }
  }
});
1 Like

@dknutsen Okay, got it. Thank you.