Categories: RxJS教程

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

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

5 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago