Can I inject service property?


#1

Just like:

Ember.inject('controller', 'currentUser', 'service:session.data.currentUser')

So I can use currentUser directly in template


#2

I don’t think you can but you could probably create a separate service called currentUser instead.


#3

I don’t think this would work either, and is probably not recommended. If you want currentUser available in every controller, what I would do is create a BaseController that does looks like the following:

// app/controllers/base-controller.js
import Ember from 'ember';

export default Ember.Controller.extend({
  session: Ember.inject.service(),
  currentUser: Ember.computed.reads('session.data.currentUser')
});

Then you would just replace all of the Ember.Controller.extend instances with BaseController.extend.

It may seem kind of tedious, you could also reopen the Ember.Controller … but I generally don’t like overriding default framework behavior :).


#4

thanks, Extend BaseController is better