javascript - 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=>{
});
}
}
解决方案
你导入是错误的。您使用了 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
推荐阅读
- android - Nativescript-vue 将光标设置在 TextInput RTL 的末尾
- javascript - 如何选择数组中的唯一元素?
- c++ - 在 OpenGL 上单击鼠标时无法旋转和更改对象的颜色
- rest - 通过 REST/SOAP 更改 LDAP 密码
- python - 如何在需要命令行参数的脚本上使用 pdoc?
- sql - 从 time_delta 列 python 中获取总秒数
- laravel - 在 laravel 刀片视图中显示刀片代码片段
- python - 来自文档字符串的 Python 函数参数签名
- python - 如何使用 python (google colab) 将人员分配到房间?
- bash - Oozie Shell Action 无法运行 Docker 容器