jeudi 28 mai 2015

In Ember.js, what is the proper way to get the current controller?

Currently, I have a mixin adding currentController property you can use to get the controller for the current route. I need it to be bindable so this is my code:

// client controller should be adding 'application' to its needs array
export default Ember.Mixin.create({

  _appController: Ember.computed.alias('controllers.application'),

  currentController: function () {
    var currentRouteName = this.get('_appController').get('currentRouteName');
    return this.controllerFor(currentRouteName);
  }.property('_appController.currentRouteName')

});

But the use of controllerFor is deprecated in favor of needs. So, how should I do? Thank you.




Aucun commentaire:

Enregistrer un commentaire