I use HTTP provider in Angular 2 for data loading from API.
return this.http.post(url, urlSearchParams.toString(), {
headers: this.getHttpHeaders()
})
.retryWhen((error) => {
return this.handleRetryError(error);
})
When there is no or old session I create new one in this.handleRetryError(error) and fill headers with it. (method getHttpHeaders() returns array with headers)
RetryWhen tries to do this post again, but there is unchanged (old) headers from first round.
Is there any chance to change headers parameter for http.post from .readyWhen?
Thank you very much for help :)
To create an observable, assign the ko. observable function to the variable. A default value can be specified in the constructor of the call. Knockout then converts your variable into a function and tracks when the value changes, in order to notify the UI elements associated with the variable.
Creating Observableslink The following example creates an Observable to emit the string 'hi' every second to a subscriber. import { Observable } from 'rxjs'; const observable = new Observable(function subscribe(subscriber) { const id = setInterval(() => { subscriber. next('hi'); }, 1000); });
RxJS' of() is a creational operator that allows you to create an RxJS Observable from a sequence of values. According to the official docs: of() converts the arguments to an observable sequence. In Angular, you can use the of() operator to implement many use cases.
You need to wrap the Observable and retry the resulting outer Observable so each time it executes again.
Observable.of(1).mergeMap(x=> {
return this.http.get('data.json', this.configObject())
.do(x => throw(x))
.map(res=>res.json());
})
.retryWhen(e => e.delay(2000))
.subscribe();
for your code
return Observable.of(1).mergeMap(x => {
return this.http.post(url, urlSearchParams.toString(), {
headers: this.getHttpHeaders()
});
})
.retryWhen(e => this.handleRetryError(e))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With