我最近将应用程序从 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/
关于angular - 为什么我在使用 rxjs 时得到 mergeMapTo is not a function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56696407/