angular - 在服务(ngOnInit 或构造函数内部)中获取数据的确切位置?
问题描述
在从我的离子角度应用程序注销时,我正在使用 auth.signOut() 方法。但是,当我注册新电子邮件时,在主页组件中,它正在从先前已签出的用户那里获取数据。看起来服务的构造函数没有被调用。当我重新加载时,它工作正常。
constructor(
private authService: AuthService,
private db: AngularFireDatabase,
) {
this.getUserId();
this.patientsRef = db.list(`/${this.loggedUserId}/patients`);
this.afPatients = this.patientsRef.snapshotChanges()
.pipe(
map(changes =>
changes.map(c => ({ id: c.payload.key, ...c.payload.val()}))
)
);
}
getUserId() {
this.authSub = this.authService.userId
.pipe(
take(1)
).subscribe(userId => {
if (!userId) {
return;
} else {
this.loggedUserId = userId.toString();
}
});
}
解决方案
您可以在auth.signOut()
. 如果您提供示例代码也会更好。
推荐阅读
- c++ - 编译时 Visual Studio 找不到 vcvars64.bat,即使它存在
- amazon-cognito - 如何建立从用户池到 aws appsync 模型的数据关系
- android - 我想在 Multipart 类中获取 SharedPreference 数据
- react-native - React Native 地图仅使用 apk 崩溃
- jquery - 占位符覆盖其他值 - 意外行为
- python - TypeError:不支持的操作数类型
- java - Java Logic 根据收到的代码更新字符串
- c++ - 初始化 Eigen::Map 的 std::array
- javascript - “debug = require('debug')('api:server')”是什么意思
- azure - 天蓝色 ARM 模板。参数 LinuxFxVersion 的值无效