RxJS:筛选运算符ignoreElements

该运算符将忽略源Observable中的所有值,仅执行对完成或错误回调函数的调用。

句法

ignoreElements()

返回值

它返回一个observable,它将根据源observable调用complete或error。

import { of } from 'rxjs';
import { ignoreElements } from 'rxjs/operators';

let all_nums = of(1, 6, 5, 10, 9, 20, 40);
let final_val = all_nums.pipe(ignoreElements());
final_val.subscribe(
   x => console.log("The last value is = "+x),
   e => console.log('error:', e),
   () => console.log('The task is complete')
);

如果成功则成功,ignoreElements()运算符将直接执行complete方法,失败则直接执行complete方法,而忽略其他所有内容。

作者:terry,如若转载,请注明出处:https://www.web176.com/rxjs/1877.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年2月9日 上午11:30
下一篇 2021年2月9日 上午11:34

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注