Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a computed property from an injected service?

I have an isAuthenticated property in a service that is currently injected on my application route, how can I have a computed property from the injected service in my route?

export default Ember.Route.extend({
    session : Ember.inject.service('market-session'),
    isUser : Ember.computed.oneWay('session.IsAuthenticated'),
}

Is this possible? In template doesn't seems to get the value.

Inside the template -

{{#if isUser}}
   User is authenticated
{{else}}
   User log in form
{{/if}}

This computed property only works if I move it to the controller, this should be working in both the route and controller right? Am I missing something here?

like image 517
abFx Avatar asked Oct 20 '22 07:10

abFx


1 Answers

Once the service has been injected, you can access computed properties on the service exactly how you have it shown above. From the Ember docs:

Creates a property that lazily looks up a service in the container. There are no restrictions as to what objects a service can be injected into.

You can access both computed properties and call functions on the service object as you would expect.

like image 109
hackerrdave Avatar answered Oct 22 '22 22:10

hackerrdave