ERROR TypeError: Cannot read properties of undefined (reading 'firestore')
- Ngôn ngữ chính
- TypeScript
- Star
- 7.8k
- Fork
- 2.2k
- Merge trung bình
- 22 giờ 28 phút
- Pull request đã merge (30 ngày)
- 6
Mô tả
### 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')
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với ví dụ UserService, đặc biệt là phần injection của Firestore, khai báo usersCollection và các entry point addUser/getIp. Tái hiện lỗi với các phiên bản Angular 17, Firebase 10 và AngularFire 18.0.1 đã nêu, sau đó xác minh rằng service có thể thêm phản hồi IP vào Firestore mà không gặp lỗi thuộc tính undefined.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, firebase, typescript
- Lĩnh vực
- databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100