[英]How to solve Angular subscribe error? Property 'subscribe' does not exist on type 'AngularFireList<unknown>'.ts(2339)
I am trying to get data from a Firebase RDB in the data service with the following function:我正在尝试使用以下功能从数据服务中的 Firebase RDB 获取数据:
this.getOrgId()
.subscribe((orgId: string) =>
localStorage.setItem('orgId', orgId));
getOrgId() {
return this.db.list(/users/${this.uId}/organization/.json);
}
Unfortunately I got the following error: Property 'subscribe' does not exist on type 'AngularFireList'.ts(2339)不幸的是,我收到以下错误: “AngularFireList”.ts(2339) 类型上不存在“订阅”属性
Does anyone has an idea how to fix it?有谁知道如何解决它? I am completely new to JS and TS.
我对 JS 和 TS 完全陌生。
Thanks a lot in advance.非常感谢。
To subscribe
to AngularFireList
you should use one of snapshotChanges()
, valueChanges<T>()
, stateChanges()
or auditTrail()
.要
subscribe
AngularFireList
您应该使用snapshotChanges()
、 valueChanges<T>()
、 stateChanges()
或auditTrail()
。
Change getOrgId()
as below.更改
getOrgId()
如下。
getOrgId() {
return this.db.list(/users/${this.uId}/organization/.json).valueChanges();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.