angular - 为什么我在使用 rxjs 时得到 mergeMapTo 不是函数?
问题描述
我最近将应用程序从 Angular 5 升级到 Angular 8,并更改了导入 rxjs 以匹配新版本的 rxjs,即 rxjs 6。
我有以下导入语句:
import { map, mergeMap, startWith, mergeMapTo } from 'rxjs/operators';
我在组件内部使用它:
public myObservable: any;
myMethod() {
this.myObservable = timer(1, 1000);
this.myObservable
.mergeMapTo(this.myService.loadData(this.myId))
.subscribe((data) => {
this.myData = data;
}, (errRes)=>{
console.log(errRes);
});
}
解决方案
您将需要使用新的 RXJS 语法,将这些运算符包装成pipe()
如下所示:
public myObservable: any;
myMethod() {
this.myTimer = timer(1, 1000);
this.myObservable
.pipe(mergeMapTo(this.myService.loadData(this.myId)))
.subscribe((data) => {
this.myData = data;
}, (errRes)=>{
console.log(errRes);
});
}
有关更多详细信息,请参阅本文:
https ://www.academind.com/learn/javascript/rxjs-6-what-changed/
推荐阅读
- python - python3如何匹配==与多个字符串
- mongodb - MongoDB - 按几个数组元素过滤
- angular - 如何在reduce angular 7中订阅状态的变化值
- c - C更新计时器而不刷新整个控制台
- android - 更新包后 Flutter Android 构建失败。AndroidX 错误
- angular - 使用 NGXS 建模方法
- python - 搜索像变量一样的数据,但我想找到像 %?% 这样的数据,但这当然行不通
- javascript - 在 Javascript 中使用 Jest 模拟整个模块
- python-3.x - 无法在 sublimetext3 中使用热键运行 py 文件
- vb.net - 选定的 ListView 项列值