简体   繁体   English

可观察的订阅-忽略下一个方法

[英]Observable subscription - Ignore next method

I don't want to do anything on next() method, I want to handle error() and complete() . 我不想在next()方法上做任何事情,我想处理error()complete()

This is my current solution that works well: 这是我目前有效的解决方案:

this.myService.myServiceObservable(params)
  .subscribe(
    () => {
      /**/
    },
    error => {
      // Handling errors here
    },
    () => {
      // Handling `complete()` here
    }
  );

I feel that this: () => { /**/ } is not the most elegant solution. 我觉得这样: () => { /**/ }不是最优雅的解决方案。

Anybody knows how to have the same result but not this ugly? 有人知道如何获得相同的结果,但丑陋吗? Am I missing something? 我想念什么吗?

You can use undefined instead of a notification handler: 您可以使用undefined代替通知处理程序:

.subscribe(undefined,
  err => { ... },
  () => { ...}
);

Or you can pass so called "PartialObserver" object that has only handlers for the notifications you want: 或者,您可以传递所谓的“ PartialObserver”对象,该对象仅具有所需通知的处理程序:

.subscribe({
  error: err => { ... },
  complete: () => { ...}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM