ERROR TypeError: Cannot read properties of undefined (reading 'firestore')
- 主要語言
- TypeScript
- 星號
- 7.8k
- 分支
- 2.2k
- 平均合併
- 22 小時 28 分鐘
- 30 天內合併 PR
- 6
描述
### Version info
**Angular:*17*
**Firebase:*10*
**AngularFire:*18.0.1*
**Other (e.g. Ionic/Cordova, Node, browser, operating system):**Angular
### How to reproduce these conditions
I am trying to insert data in firebase but getting error
import { Injectable, inject } from '@angular/core';
import { Firestore, collection, collectionData, addDoc, CollectionReference, DocumentReference} from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UserService {
private ipApiUrl = 'https://ipapi.co/json/';
private firestore: Firestore = inject(Firestore);
usersCollection!: CollectionReference;
constructor(private http: HttpClient) {
}
async addUser() {
let user = await this.getIp
}
getIp() {
this.http.get(this.ipApiUrl).subscribe(ipDetails => {
addDoc(this.usersCollection, ipDetails).then((documentReference: DocumentReference) => {
console.log(documentReference,'popopopo')
})
})
}
}
### Debug output
** Errors in the JavaScript console **
ERROR TypeError: Cannot read properties of undefined (reading 'firestore')
貢獻指南
研究方向
從 UserService 範例開始,特別注意 Firestore 注入、usersCollection 宣告以及 addUser/getIp 進入點。使用所述的 Angular 17、Firebase 10 和 AngularFire 18.0.1 版本重現錯誤,然後確認該服務可以將 IP 回應新增至 Firestore,而不會出現 undefined 屬性錯誤。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- angular, firebase, typescript
- 領域
- databases
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100