首页 > 解决方案 > read.ts(6133) 模块 '"../../../node_modules/rxjs/observable/combineLatest"' 没有导出的成员 'combineLatest'.ts(2305)

问题描述

如何通过 combineLatest 组合 Observables。combineLatest 未定义

我正在使用 Angular js 7。我想对两个查询字符串参数进行 marge,但是当我编写 obserable.combinelaste([]) 时,它会给出错误。

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, of, observable } from 'rxjs'
import { combineLatest } from 'rxjs/observable/combineLatest';
@Component({
  selector: 'app-githubfollowers',
  templateUrl: './githubfollowers.component.html',
  styleUrls: ['./githubfollowers.component.css']
})
export class GithubfollowersComponent implements OnInit {

  constructor(private rout:ActivatedRoute ) { }

  ngOnInit() {
    Observable.combineLatest([  this.rout.paramMap,
  this.rout.queryParamMap

    ]);

    this.rout.paramMap.subscribe(prams=>{

    });
    this.rout.queryParamMap.subscribe(prams=>{

    });
  }

}

标签: javascripthtmlangularrxjs

解决方案


你导入是错误的。您使用了 RXJS v5 的导入。

对于 RxJS v6+,你应该使用这个 import :

import { combineLatest } from 'rxjs';

要解决以下错误消息:

ngOnInit() { Observable.combineLatest([ this.rout.paramMap, this.rout.queryParamMap ]); “typeof Observable”类型上不存在属性“combineLatest”

你可以combineLatest这样使用:

combineLatest(this.rout.paramMap, this.rout.queryParamMap)

你可能需要花一些时间来阅读如何使用它:https ://www.learnrxjs.io/operators/combination/combinelatest.html


推荐阅读