【发布时间】:2020-04-26 19:47:28
【问题描述】:
所以我想从订阅中返回一个值:
export class UserHomePage implements OnInit {
uid: string;
...
constructor(
private afAuth: AngularFireAuth,
private afs: AngularFireStore,
...
) {}
getAuth() {
return this.afAuth.authState.subscribe(auth => { <= // It's ok
this.uid = auth.uid;
console.log('ID : ' + this.uid);
});
}
我尝试在其他函数中使用“this.uid”,但数据是“未定义”:
example() { <= // Problem !
console.log(this.uid);
}
我只是在这个论坛上找到了另一个主题here,但我不明白可观察的方式。
你能解释一下如何为下一个函数返回这些数据吗?
谢谢(对不起我的英语)!
【问题讨论】:
标签: angular ionic-framework return observable subscribe