问题
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