Mar*_*bis 8 javascript rxjs angularjs rxjs5 angular
完整的回调没有按预期工作。让我解释:
看到这张图片,注意方法中的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 not called, why god??
}
);
Run Code Online (Sandbox Code Playgroud)
用来:rxjs 6pipe/finalize
import { finalize } from 'rxjs/operators';
this.getData(params)
.pipe(
finalize(() => {
// this is called on both success and error
})
)
.subscribe(
(successData) => { },
(err) => { }
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19571 次 |
| 最近记录: |