vendredi 20 mai 2016

Ember service is lost on reload

I'm using Ember.Service as a long-lived ember object cause I need it to be available in different parts of my application.

import Ember from 'ember';

export default Ember.Service.extend({
    user:null,
    updateActiveUser(user){
        this.set('user',kid);
    },
    getActiveUser(){
        const user=this.get('user');
        if(user){
            return user;
        }else{
            return null;
        }   
    }
});

On my component I'm asking for this user in this way: import Ember from 'ember';

export default Ember.Component.extend({
activeKid:Ember.inject.service('active-user'),
list: [],
selectedUser:null,
didReceiveAttrs() {
    this._super();
    this.set('list',this.get('model'));
    const active=this.get('activeUser').getActiveUser();
    if(active){
        this.set('selectedUser',active);
    }else{
        this.set('selectedUser',this.get('model').objectAt(0));
    }
},
actions:{
    selectUser(user){
        this.set('selectedUser',user);
        this.get('activeUser').updateActiveUser(user);

    }
}
});

My issue is that after I select a user and then I reload the page is not saving the last user selected and its showing the default user.




Aucun commentaire:

Enregistrer un commentaire