app.component.html as you can see I'm trying to show response data of my firebase project by *ngFor
<div class="row">
<div class="col-md-3">
<h4 class="text-warning">All Employee Data</h4>
<div class="card" *ngFor="let item of employee">
<div class="card-body">
<div class="card-title">
Name: {{item.name}} // error-Property 'name' does not exist on type 'never'.
</div>
<div class="card-subtitle">
Age: {{item.age}} // error-Property 'name' does not exist on type 'never'.
</div>
<div class="card-text">
Address: {{item.address}} // same error here also
</div>
</div>
</div>
</div>
</div>
app.component.ts as you can see I'm trying to fetch data from firesbase project.
export class AppComponent implements OnInit {
title = 'App';
constructor( private _crudService:CrudService) {}
employee:[] = [];
employeeName: string = '';
employeeAge: number | undefined;
employeeAddress: string = '';
message: string ='';
ngOnInit(){
this._crudService.getAllEmployee().subscribe((data:any) =>{
this.employee = data.map((e:any) =>{ // here I'm storing res in empty array
return{
id: e.payload.doc.id,
name: e.payload.doc.data()['name'],
age: e.payload.doc.data()['age'],
address: e.payload.doc.data()['address']
}
});
console.log(this.employee);
});
}
crud.service.ts as you can see I'm sending request to get Employee Data
getAllEmployee(){
return this.fireservice.collection('Employee').snapshotChanges();
}
e.payload.doc.data.name
instead ofe.payload.doc.data()['name']
in ngOnInit – vivek