RxJS - 过滤运算符 ignoreElements

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

语法

ignoreElements()

返回值

它返回一个可观察对象,该可观察对象将根据源可观察对象调用完成或错误。

示例

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() 操作符将在成功时直接执行完整方法,如果失败则执行错误,并忽略其他所有内容。

输出

ignoreElements Operator