I encountered an issue while attempting to retrieve all data from the Firebase real-time database:
After removing async
from the template, the error disappeared but no data was fetched! I'm confused about what exactly is causing this problem!!
This is my TypeScript code:
tutos?:Tutorial[];
retrievetutos(): void {
this.menuService.getAll().snapshotChanges().pipe(
map(changes =>
changes.map(c =>
({ key: c.payload.key, ...c.payload.val() })
)
)
).subscribe(data => {
this.tutos = data;
});
}
HTML:
<tr *ngFor="let tuto of tutos | async">
<td>{{tuto.name}}</td>
<td>{{tuto.price}}</td>
</tr>
The Error:
Error: src/app/components/dashboard/dashboard.component.html:49:37 - error TS2769: No overload matches this call.
Overload 1 of 3, '(obj: Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined>): any[] | ... 2 more ... | undefined', gave the following error.
Argument of type 'any[] | undefined' is not assignable to parameter of type 'Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined>'.
Type 'undefined' is not assignable to type 'Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined>'.
Overload 2 of 3, '(obj: null | undefined): null', gave the following error.
Argument of type 'any[] | undefined' is not assignable to parameter of type 'null | undefined'.
Overload 3 of 3, '(obj: Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined> | null | undefined): any[] | ... 2 more ... | undefined', gave the following error.
Argument of type 'any[] | undefined' is not assignable to parameter of type 'Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined> | null | undefined'.
Type 'any[]' is not assignable to type 'Observable<any[] | Iterable<any> | undefined> | Subscribable<any[] | Iterable<any> | undefined> | Promise<any[] | Iterable<any> | undefined> | null | undefined'.
Type 'any[]' is missing the following properties from type 'Observable<any[] | Iterable<any>': source, operator, lift, subscribe, and 2 more.
49 <tr *ngFor="let tuto of tutos | async">
~~~~