我正在 Angular 2 组件中执行 2 个 http 调用。我想在这两个服务调用完成后显示成功消息。我怎样才能做到这一点?
this._cashierService.postCharge(this.postCharge).subscribe( resPostCharge => {
this.footerNotification.success('Save', 'Successfully saved'); //i want to show this after 2 calls finished
}, errorMessage => {
});
this._cashierService.splitCharge(this.postCharge).subscribe( resPostCharge => {
this.footerNotification.success('Save', 'Successfully saved');
}, errorMessage => {
});
最佳答案
链接可观察对象,以便它可以逐个调用并在最后一个中打印控制台。从第一个观察者订阅返回第二个调用。
this._cashierService.postCharge(this.postCharge)
.subscribe(resPostCharge => {
return this._cashierService.splitCharge(this.postCharge);
}, errorMessage => {
})
.subscribe(resPostCharge => {
this.footerNotification.success('Save', 'Successfully saved');
}, errorMessage => {
});
关于javascript - Angular 2 在所有http调用完成后做一些事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45209535/