Can I inject service property?

Just like:

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

So I can use currentUser directly in template

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

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 :).

3 Likes

thanks, Extend BaseController is better