简体   繁体   English

如何解决 Angular 订阅错误? 类型“AngularFireList”上不存在属性“订阅”<unknown> &#39;.ts(2339)

[英]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.

相关问题 类型 'void | 上不存在属性 'subscribe' 可观察的<user> '。 ts(2339)</user> - Property 'subscribe' does not exist on type 'void | Observable<User>'. ts(2339) Angular。 TS2339:“无效”类型上不存在属性“订阅” - Angular. TS2339: Property 'subscribe' does not exist on type 'void' 我该如何解决“'元素'类型上不存在属性'checkValidity'。” ts(2339) 错误 - How can i solve a "Property 'checkValidity' does not exist on type 'Element'." ts(2339) error 类型“未知”.ts(2339) 上不存在属性“名称” - Property 'name' does not exist on type 'unknown'.ts(2339) Angular 7中的类型&#39;OperatorFunction &lt;{},{}&gt;&#39;错误上不存在属性&#39;subscribe&#39; - Property 'subscribe' does not exist on type 'OperatorFunction<{}, {}>' error in Angular 7 角度2中的类型&#39;void&#39;上不存在属性&#39;subscribe&#39; - Property 'subscribe' does not exist on type 'void' in angular 2 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** 错误TS2339:类型“ {}”上不存在属性“ forEach” - error TS2339: Property 'forEach' does not exist on type '{}' 错误TS2339:类型“ HTMLElement”上不存在属性“名称” - error TS2339: Property 'name' does not exist on type 'HTMLElement' 错误 TS2339:“温度”类型上不存在属性“摄氏度” - error TS2339: Property 'celsius' does not exist on type 'Temperature'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM