我正在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/

10-12 00:25
查看更多