【发布时间】:2019-04-15 00:43:48
【问题描述】:
我有一个 Angular 函数,我试图通过将用户的凭据与数据库进行比较来测试用户是否有效:
isLoggedIn() {
this.userService.getUser(this.user.userName)
.pipe(first())
.subscribe(
result => {
this.currentUser = result;
if (this.currentUser.fullName != result.fullName) {
return false
}
return true;
},
() => { });
console.log('The function shouldn't go here')
}
如何让函数等待我的订阅完成?现在它直接进入 console.log 行并返回 false,然后从 api 调用中获取结果
【问题讨论】:
标签: angular typescript