Hi there!
I am getting this error fetching data from firebase.
ERROR TypeError: Cannot read properties of undefined (reading ‘name’)
Anybody can help me to solve this problem?
Here is the codes:
service.component.ts
export class FirebaseService {
firebaseUrl = 'https://corsoangular-xxxxx-default-rtdb.europe-west1.firebasedatabase.app/service.json';
constructor(private http: HttpClient) { }
getService():Observable<any> {
return this.http.get(this.firebaseUrl)
}
}
component.ts
export class ListComponent implements OnInit{
firebaseUrl!: any[];
constructor(private firebase: FirebaseService){}
ngOnInit(): void {
this.firebase.getService().subscribe((data: any) => {
this.firebaseUrl = Object.keys(data).map((key) => {return data[data]})
console.log(data)
console.log(this.firebase)
})
}
}
component.html
<div *ngFor="let user of firebaseUrl">
<p>{{user.name}}</p> <p>{{user.email}}</p>
</div>