I want to wait within a method till a promise return.
public loginOffline(username: string, password: string) {
return this.database.getItem('currentUser', 'login').then(data => {
this.userLogin = data;
console.log(username + ' ' + this.userLogin.username + ' ' + password + ' ' + this.userLogin.password);
if (username === this.userLogin.username && password === this.userLogin.password) {
return true;
} else {
return false;
}
}).catch(err => {
return false;
});
}
/********* call the method and descide what to do **************/
if (loginOffline('myname', 'mypassword'){
// Do something.....
} else {
// Do something else .....
}
......
this doesn't work. The method to call this loginOffline method just want to know if the login in was successful. I tried many things but nothing worked out.
Can anybody help. Thanks a lot Cheers
You just have to chain the promise with another then
.
Call this way:
loginOffline('myname', 'mypassword').then(result =>{
if(result){
//do something
}else{
//do something else
}
})
More on promise chaining
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With