我有一个调用“getUserDocInfo()”的组件,它在它自己的服务中。我将如何调用该函数,然后将返回的数据用于进一步的代码?
我的组件
getToken(){
this.userService.getUserDocInfo();
// once this is called I would like to use some of the values in the returned data
}
我的服务
getUserDocInfo() {
this.getUserInfo().then(() => {
this.userDoc = this.afs.doc(`users/${this.userID}`);
this.user = this.userDoc.snapshotChanges();
this.user.subscribe(value => {
const data = value.payload.data();
});
})
}
async getUserInfo() {
const user = await this.authService.isLoggedIn()
if (user) {
this.userID = user.uid;
} else {
// do something else
}
}
任何有关最佳实践的帮助将不胜感激。