I am looking for a way to use a loading bar component
on an observable stream
?
I have a component
that displays data from an observable
using the async pipe
. This Observable can also manipulate the data such as using map.
Currently I have this in component:
this.listData$ = this.http.get('/itemList')
.map(data => this.manipulate(data))
and in template:
{{listData$ | async}}
The server can return the data as empty []
, 'unavailable'
or array
of items.
How can I tap into the stream and feed a loading component that would display a loading bar when loading the data, and display error messages when empty or unavailable? Something along the lines of...
this.listData$ = this.http.get('/itemList')
//.something here??
.map(data => this.manipulate(data))
<loading-bar [data]='listData$' [noDataMsg]='"no data"' [errorMsg]='unavailable'>
{{listData$ | async}}
</loading-bar>
Ideally I would like to keep using the async pipe
and not subscribe in my component. But, passing the Observable to the loading-bar component and subscribing in there, that makes 2 http calls
...then I need to .share()
on the Observable...
What approach do you guys take to display loading, no data and error messages with your streams?