我没有得到带有间隔、switchMap 和 map 的 angular 6 的 rxjs 6 [英] I dont get rxjs 6 with angular 6 with interval, switchMap, and map

查看:18
本文介绍了我没有得到带有间隔、switchMap 和 map 的 angular 6 的 rxjs 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 rxjs 代码更新为 6 我不明白.

I want to update my rxjs code to 6 got I don't get it.

在我每 5 秒轮询一次新数据之前:

Before I had the below that wouth poll for new data every 5 seconds:

import { Observable, interval } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';

var result = interval(5000).switchMap(() => this._authHttp.get(url)).map(res => res.json().results);

现在……当然,它坏了,文档让我无处可去.

Now...of course, it's broken and the documentation leaves me nowhere to go.

如何编写以上内容以符合 rxjs 6?

How do I write the above to conform to rxjs 6?

谢谢

推荐答案

代码应该类似于以下内容.您需要使用 pipe 运算符.

The code should be something like the following. You need to use the pipe operator.

import { interval } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';

const result = interval(5000).pipe(
switchMap(() => this._authHttp.get(url)),    
map(res => res.results)
)

这篇关于我没有得到带有间隔、switchMap 和 map 的 angular 6 的 rxjs 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆