angular - 错误:“void”类型上不存在属性“then”
问题描述
当用户想要登录移动应用程序时,我试图从 Firebase 实时数据库中获取一些用户状态信息(isDeleted:true/false)。在尝试这个时,我得到了这个错误:
“void”类型上不存在属性“then”
代码如下所示:
登录页面.ts
loginUser() {
const data = this.loginForm.value;
if (!data.userName) {
return;
}
this.loadingCtrl.create({
message: 'Loading...'
}).then((res) => {
res.present();
});
const credentials = {
email: data.userName + this.username_domain,
password: data.password
};
this.authService.loginUser(credentials)
.then(res => {
this.userService.setOrgId(res.user.photoURL);
this.loadingCtrl.dismiss();
this.router.navigateByUrl('/tabs');
//The error occours here.
this.userService.getUserStatus().then((isDeleted: any) => {
console.log('isDeleted ', isDeleted)
if (isDeleted) {
err => {
this.loadingCtrl.dismiss();
this.toast = this.toastCtrl.create({
message: 'Your account is not active anymore.',
duration: 2000
});
}
this.authService.logoutUser()
.then(async (res) => {
this.clearLocalData();
this.navCtrl.navigateRoot('login');
})
.catch(error => {
console.log(error);
});
}
});
}, err => {
this.loadingCtrl.dismiss();
this.toast = this.toastCtrl.create({
message: err.message,
duration: 2000
}).then((toastData) => {
toastData.present();
});
});
}
用户服务.ts
getUserStatus() {
firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get().then(function(snapshot) {
if (snapshot.exists()) {
console.log(snapshot.val());
}
else {
console.log("No data available");
}
}).catch(function(error) {
console.error(error);
});
}
有谁知道如何修理它?
解决方案
getUserStatus()
不返回任何内容,您必须执行以下操作:
getUserStatus() : Promise<DataSnapshot> {
return firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get();
}
推荐阅读
- python - 如果 pandas 中另一个数据框的列名中存在行名,则选择数据框的行值
- php - 如何将参数从播种机传递给工厂?
- python - 如何在 plotly 中制作动画 3D 散点图
- python - Python 读取日期时间字符串(使用 python 读取 T01:00:00-07:00)
- java - 在我的布局中有recyclerview和底部导航栏,但导航栏位于recycler view的后面
- typescript - 如何根据 TypeScript 中另一个参数的值来优化参数的类型?
- java - java - 如何在Java中将一个列表值列出到另一个列表值?
- reactjs - 我如何在 Jest 中测试这个?
- javascript - 按时间顺序对月份的对象进行排序?
- sql-server - 无法对具有聚集列存储索引的表启用更改数据捕获。考虑删除聚集列存储索引