ERROR TypeError: Cannot read properties of undefined (reading 'firestore')
- Dominant language
- TypeScript
- Stars
- 7.8k
- Forks
- 2.2k
- Avg merge
- 22h 28m
- Merged PRs (30d)
- 6
Description
### 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')
Contributor guide
Research direction
Start with the UserService example, especially the Firestore injection, usersCollection declaration, and addUser/getIp entry points. Reproduce the error with the stated Angular 17, Firebase 10, and AngularFire 18.0.1 versions, then verify that the service can add the IP response to Firestore without the undefined-property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, firebase, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100