Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为什么在使用rxjs时,我得到的mergeMapTo不是一个函数?_Angular_Rxjs6_Angular Observable - Fatal编程技术网

Angular 为什么在使用rxjs时,我得到的mergeMapTo不是一个函数?

Angular 为什么在使用rxjs时,我得到的mergeMapTo不是一个函数?,angular,rxjs6,angular-observable,Angular,Rxjs6,Angular Observable,我最近将应用程序从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);

我最近将应用程序从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语法,方法是将这些运算符包装到
管道()

像这样:

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);
            });
      }
有关更多详细信息,请参阅本文: