ionic 3 - can't store to storage after http request

…衆ロ難τιáo~ 提交于 2020-01-16 17:02:07

问题


I already read the docs regarding Ionic Storage and have already imported what is needed. But still can't seem to get it to work. When I check the localStorage of chrome (I use 'ionic cordova run browser'), it's empty.

Here's my code:

cordova.plugin.http.sendRequest('http://127.0.0.1:5000/api/login/', options, function(response) {

        try {   //onSuccess
            response.data = JSON.parse(response.data);

            this.store.set('token', JSON.stringify(response.data.token));

            this.navCtrl.setRoot(HomePage);

          } catch(e) {
            console.error('JSON parsing error');
          }
        },  function(response) {    //onFail
            console.log('403');
            alert.present();

        }
    );

My constructor looks like this:

constructor(public navCtrl: NavController,
            private alerts: AlertController, 
            private http: HTTP, 
            private store: Storage, 
            ) {}

When I run it, it throws an error and shows 'JSON parsing error' instead of rerouting to HomePage. What am I doing wrong here? Please help

来源:https://stackoverflow.com/questions/49962732/ionic-3-cant-store-to-storage-after-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!