I have a problem, when I login to the application. Native storage on Ionic keeps the login result data well but when I close my application, the data on nativestorage
is gone and also I’m not trigger this.nativeStorage.remove()
command. Anyone know what cause this? And how to solve it? i’m using ionic 3
This is the login data when I logged in
{
"phonenumber":"12341234",
"username" : "bingo"
}
but when I close the application
{
"phonenumber":"",
"username":""
}
the declaration variable
login : any ={
phonenumber : '',
username : '',
}
the set function
SetLogin(_login : any)
{
this.login.phonenumber = _login.phonenumber;
this.login.username = _login.username;
this.nativeStorage.setItem('Loginmodel',this.login );
}
the get function
GetLogin()
{
this.nativeStorage.getItem('Loginmodel') .then(
data => {
console.log(data);
this.login = data;
},
error => console.error(error)
);
return this.login;
}
this is when i trigger the function
googlelogin(){
this.google.login({})
.then(res => {
this.model.id = res.userId;
this.logincekfbgo('2',res.userId);
})
.catch(err => alert('fail')+err);
}
logincekfbgo(lg:any,id:any){
this.loading.present();
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let data=JSON.stringify({lg:lg,id:id});
this.http.post(this.pf.getLink('auth'),data,{headers: headers})
.map(res => res.json())
.subscribe(res => {
this.loading.dismissAll();
if(res.rc =="00")
{
this.pf.Popup(res.rcdesc);
if(res.isregister=="0"){
this.navCtrl.push(InputnumberPage,{
id : this.model.id,
username:this.model.username,
email:this.model.email,
islg:lg,
tgl : ''
});
else{
this.lgm.SetLogin(res.lgm);
this.navCtrl.push(MenuTabPage);
}
}
else
{
this.pf.Popup('fail');
}
}
else
{
this.pf.Popup(res.rcdesc);
}
}, (err) => {
this.loading.dismissAll();
alert("failed");
});
this.loading.dismissAll();
}