jeudi 15 juin 2017

Reading a computed property injected by a service with handlebars in ember.js

I am trying to mutate my handlebars scripts by using a computed isAuthenticated property injected via a custom auth service. In the my-application component, this works with little problem via the following code:

      
        <li>My Account</li>
        <li>Find other Medici Users</li>
      

import Ember from 'ember';

export default Ember.Component.extend({
  auth: Ember.inject.service(),
  user: Ember.computed.alias('auth.credentials.email'),
  isAuthenticated: Ember.computed.alias('auth.isAuthenticated'),

  actions: {
    signOut () {
      this.sendAction('signOut');
    },
  },
});

When I try to implement this exact same code in a different location (in this case, the accounts route) as such:

<button type="btn" >test</button>


<p>test</p>




import Ember from 'ember';

export default Ember.Route.extend({
  auth: Ember.inject.service(),
  user: Ember.computed.alias('auth.credentials.email'),
  isAuthenticated: Ember.computed.alias('auth.isAuthenticated'),

  actions: {
    test () {
      console.log(this.get('user'));
      console.log(this.get('isAuthenticated'));
    }
  }
});

There is no change in the template (though test does appear when you switch the if out with an unless). Making this all the stranger is the fact that, when I click the test button, it successfully fires the result of isAuthenticated. Why am I unable to transfer this property over from my js file to my hbs file?




Aucun commentaire:

Enregistrer un commentaire