jeudi 9 février 2017

Ember findRecord doesnot make API call when reload is true

When route is called, a method "load" is called which fetches data to display details of user.(using "this.store.findRecord" to fetch the user)

In that page, on button click am making an ajax call from controller, after success i am trying to bring updated values of user by calling the previous method "load". this time method is getting called but "this.store.findRecord" is not making call to the backend.

current-user (service which contains load method)

 user: null,
 load(){
   window.u = this;
   if(this.get('session.isAuthenticated')){
     console.log('reload user');
     this.get('store').findRecord('user', 'me', {reload:true}).then(user => {
     this.set('user', user);
   });

   } else {
    console.log('not reloading user');
   }
}

The above method will be called when the page loads for the first time and also in the success part of ajax call

Ajax call

ajax: Ember.inject.service(),
currentUser: Ember.inject.service('current-user'),

init(){
    this._super(...arguments);
},

actions:{
    recharge(amount){
        console.log(amount);
        var user_id = this.get('currentUser').get('user').get('id');
        var balance = this.get('currentUser').get('user').get('balance');
        var that = this;
        console.log(this.get('currentUser').get('user'));
        this.get('ajax').post('/user/payments', {data: {user_id: user_id, amount:amount}})
        .then(() => {
            console.log("successfully recharged");
            this.get('currentUser').load();
        }).catch(() => {
            console.log("Something went wrong");
        });
    }
}




Aucun commentaire:

Enregistrer un commentaire