我想在方法中等待,直到承諾返回。等待承諾完成並返回true或false
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 .....
}
......
這不起作用。調用此loginOffline方法的方法只是想知道登錄是否成功。我嘗試了很多東西,但沒有成功。
任何人都可以幫忙。非常感謝 乾杯
THX了很多的工作完全按照我的願望。 –