Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在服务内部(ngOnInit或构造函数内部)获取数据的确切位置?_Angular_Firebase_Ionic Framework_Rxjs_Firebase Authentication - Fatal编程技术网

Angular 在服务内部(ngOnInit或构造函数内部)获取数据的确切位置?

Angular 在服务内部(ngOnInit或构造函数内部)获取数据的确切位置?,angular,firebase,ionic-framework,rxjs,firebase-authentication,Angular,Firebase,Ionic Framework,Rxjs,Firebase Authentication,从我的应用程序注销时,我正在使用auth.signOut metohd。但是,当我注册新的电子邮件时,在home组件中,它正在从以前登录的用户获取数据。看起来服务的构造函数没有被调用。当我重新加载时,它工作正常 constructor( private authService: AuthService, private db: AngularFireDatabase, ) { this.getUserId(); this.patientsRef = db.list(`/${this.logged

从我的应用程序注销时,我正在使用auth.signOut metohd。但是,当我注册新的电子邮件时,在home组件中,它正在从以前登录的用户获取数据。看起来服务的构造函数没有被调用。当我重新加载时,它工作正常

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内调用unsubscribe。另外,如果您提供示例代码也会更好。

您能显示您当前的代码吗?我不确定要显示什么代码。我有多个从firebase获取用户数据的服务。在每个服务的构造函数中,我获取当前记录的userId,然后获取该用户的数据。但当我注销并再次与不同的用户登录时,似乎并没有调用构造函数。如何纠正这一点?