Ruzel R.
Ruzel R.

Reputation: 327

How to access another controller's action from another controller

I have just upgraded my Ember application to the newest version, but then while testing its functionality, some actions doesn't work. My previous code which is working fine in older version is below.

export default Ember.Controller.extend({
needs: 'sales-order',
actions: {
    showModal: function(mode){
        this.get('controllers.sales-order').send('showModal', mode);
    }
  }
});

Looks like the "needs" is depreciated.

Upvotes: 1

Views: 599

Answers (1)

locks
locks

Reputation: 6577

Instead of needs you should use Ember.inject.controller. It should look something like this:

export default Ember.Controller.extend({
  salesOrder: Ember.inject.controller(),

  actions: {
    showModal(mode) {
      this.get('salesOrder').send('showModal', mode);
    }
  }
});

You can find more information in the Managing Dependencies Between Controllers guide.

Upvotes: 5

Related Questions