I have a angular 4 app. In this app I have a paypal service, which does some server work and navigates (from client) to paypal.
@Injectable()
export class PaypalService {
private readonly http: HttpApi;
constructor(private readonly httpFactory: HttpFactoryService) {
this.http = httpFactory.get(HttpRequestType.Secured);
}
checkout(transactionId: string):
Observable<Response> {
let subscriber = this.http.post(environment.paymentServer + '/pay', {transactionId: transactionId})
subscriber.subscribe((response:Response) => {
let result = response.json();
window.location.href = result.paymentUrl;
});
return subscriber;
}
}
I want the window.location.href will be called only after all subscribers was notified.
paypal.checkout("1234").subscribe(() =>
//This code should be called before the navigation will start
doSomeCleaning())
I know I can use delay, but I was wondering if there is a better option.
flatMapoperator for example and at end to have only one subscribe method from which you can call the redirect. - Yordan Nikolov