Service computed properties and templates


#1

I am attempting to write a service that depends on Torii (which itself provides two different services, torii and session). My service has a computed property like so:

// app/services/foo-bar.js
import Ember from 'ember';

export default Ember.Service.extend({
  session: Ember.inject.service(),

  quux: Ember.computed('session.currentUser', function () {
    return `user#${this.get('session').get('currentUser')}`;
  })
});

I inject the service into my application route:

// app/routes/application.js
import Ember from 'ember';

export default Ember.Route.extend({
  session: Ember.inject.service(),
  fooBar: Ember.inject.service('foo-bar')
});

But fooBar.quux is not available in my template, and this.get('fooBar').get('quux') is not available in the beforeModel() hook of the route. It is, however, available in the model() hook, so I’m making it available to my template through there as a workaround:

// app/routes/application.js
import Ember from 'ember';

export default Ember.Route.extend({
  session: Ember.inject.service(),
  fooBar: Ember.inject.service('foo-bar'),

  model: function () {
    return this.get('fooBar').get('quux');
  }
});

What can I do to make the computed properties of my service available directly in the template, without having to go through the model? I’m on Ember 2.0 and Torii 0.6.0. Thanks in advance.


#2

@rwjblue set me straight, I simply need to inject the service on my application controller, and et voilà. It works!