0
我使用Angularfire2库在用户登录并获取从火力地堡数据库中的数据,但是当用户点击退出以下错误抛出到控制台后抛出:AngularFire2错误注销用户
不能读取线零的特性“UID”
这里是uid
财产在ngOnInit
方法任务组件的2线引发错误:
ngOnInit() {
this.authSub1 = this.auth.authState.subscribe((auth) => {
this.tasksSub = this.af.list(`users/${auth.uid}/tasks`, { preserveSnapshot: true }).subscribe(snapshots => {
snapshots.forEach(snapshot => {
this.tasksArray.push(snapshot.val().name);
});
});
}, (err) => {this.openSnackBar(); console.log(err); });
}
然后我打电话unsbuscribe
上述订阅,以避免在ngOnDestroy
方法内存泄漏:
ngOnDestroy() {
this.authSub1.unsubscribe();
}
这里是由位于主成分(的路由器出口处的按钮来触发登出方法主要成分是显示上述组件):
logout() {
this.auth.auth.signOut()
.then(() => {
this.router.navigateByUrl('/login');
})
.catch(function(err) {console.log(err); });
}