小编Mar*_*bis的帖子

Angular 2 中 Observable.prototype.subscribe 的完整回调

完整的回调没有按预期工作。让我解释:

看到这张图片,注意方法中的complete回调subscribe。此complete函数仅在调用时observerOrNext调用。当发生某些错误时,complete不会调用 。这是对的?还有另一种方法可以获取在进程完成时始终调用的回调?

在此处输入图片说明

例子:

成功时:

this.getData(params)
    .subscribe(
        successData => {
            // this is called
        },
        error => {
            // this is not called. Ok!
        },
        () => { // when complete
            // this is called, ok!
        }
    );
Run Code Online (Sandbox Code Playgroud)

出错时:

this.getData(params)
    .subscribe(
        successData => {
            // this is not called, ok!
        },
        error => {
            // this is called. Ok! Yeah!
        },
        () => { // when complete
            // this is …
Run Code Online (Sandbox Code Playgroud)

javascript rxjs angularjs rxjs5 angular

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1

angularjs ×1

javascript ×1

rxjs ×1

rxjs5 ×1