I'm attempting to simulate latency with my observables.
I want to unwrap the observable using the async pipe, and add a bit of delay with the 'delay' operator.
app.component.html
<ul *ngIf="items$ | async as items">
<li *ngFor=let item of items">{{ item }}<li>
</ul>
app.component.ts
get items$(): Observable<string[]> {
return of(['alpha', 'bravo', 'charlie', 'delta']).pipe(delay(3000));
}
However, doing it in this fashion returns no HTML markup. Removing the pipe(delay(3000))
allows it to work.
If I implement 'OnInit' and just check on the observable:
ngOnInit(): void {
this.items$.subscribe(val => console.log(val));
}
In three seconds the console will output:
(4) ["alpha", "bravo", "charlie", "delta"]
So the observable is behaving like I want it to, but it seems I am not utilizing the async pipe correctly.
What am I missing about about how the async pipe works? How do I simulate this delay in a simple fashion?