Angular2 observable http get conditional repeat
I am using angular2 observable pattern to make http requests. I am trying to conditionally retry http get: I want to execute http get until the condition is met:
http.get('url')
.map(res => {
// if the condition is met I should repeat the http get request
})
.subscribe()
Is there a way to conditionally repeat the http get request?
Thanks, Marco
+3
Marco Antelmi
source
to share
1 answer
You can use expand . Here's an example:
let request$ = http.get('url');
request$.expand(value => {
return value !== 0 ? request$ : Rx.Observable.empty()
})
.map(res => {
//Do mapping here
})
.subscribe()
+5
AhmedRiyad
source
to share