lundi 26 octobre 2015

How to call an action on the app route from any component without having to pass it everywhere?

I'd like to be able to open a login modal from any component without having to pass it through the component hierarchy each time I need it.

The openModal action on the application is the same as in the modal cookbook in the guides :

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    openModal: function(modalName) {
      return this.render(modalName, {
        into: 'application',
        outlet: 'modal'
      });
    }
  }
});

I would like to avoid :

{{my-component openModal="openModal" otherArgs=args ... }}

Plus import Ember from 'ember';

export default Ember.Component.extend({
  actions: {
    openModal(modalName) {
      this.sendAction('openModal', modalName);
    }
  }
});

I could use a service injected in each component, but then how to call the openModal action on the application route from the service ?

Thanks !




Aucun commentaire:

Enregistrer un commentaire