Trying to mimic the HTTP requests, and to make a static data to be presented with the async pipe.
ts:
footerContent$: Observable<{ key: string, value: string }>[] = ([
of({ key: '1', value: 'a' }),
of({ key: '2', value: 'b' }),
of({ key: '3', value: 'c' })
])
HTML:
<div *ngFor='let content of footerContent$ | async'>
{{content.value}}
</div>
Here I'm getting an Array of Observables and the pipe doesn't seem to work
ERROR Error: InvalidPipeArgument: '[object Object],[object Object],[object Object]' for pipe 'AsyncPipe'
Then i tried another approach and switch to from operator (so i can get one observable object):
footerContent$: Observable<{ key: string, value: string }> = from([
({ key: '1', value: 'a' }),
({ key: '2', value: 'b' }),
({ key: '3', value: 'c' })
])
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoChec
Any suggestions why it doesn't work?
async pipeis used to subscribe to an Observable directly from the template. In your first example you're dealing with an array not an Observable. In your second example your Observable emits multiple Objects and not an Array, so usingngFordoesn't work there. I'm not sure what you're trying to do exactly. In your first example you could wrap the array of Observables withforkJoin, in your second example you could useofinstead offrom.