2
votes

How do I use a dependency injected field in another field within the ember controller in 2.x Ember?

For instance, I have

  export default Ember.Controller.extend({
     session: Ember.inject.service('session'),
     user: this.get('session').username

How is user able to access the lazily computed values of session?

I noticed that the case above doesn't work as I believe the value of session has been computed yet?

I could use a computed property but I use user as a value in input and I am merely setting a base value.

1

1 Answers

0
votes

Not sure if I understood your question correctly, but it seems like you could use computed property function (I usually handle it this way when it comes to DI):

user: Ember.computed.oneWay('session.username')

Or simpler, alias:

user: Ember.computed.alias('session.username')