angular - “typeof Observable”类型上不存在属性“forkJoin”。角 8
问题描述
我正在尝试使用方法 forkJoin 执行多个 http 请求。我需要像一个简单的请求一样返回所有值,但我遇到了一些错误。
我使用的是角度版本 8.2.3,我的 rxjs 版本是 ~6.3.3
查看我的服务代码:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map, catchError } from 'rxjs/operators';
import 'rxjs/add/observable/forkJoin';
import { Observable } from 'rxjs';
const PRAGMA = 'pragma';
const NO_CACHE = 'no-cache';
const CACHE_CONTROL = 'Cache-Control';
const URL = 'https://pokeapi.co/api/v2/';
@Injectable({
providedIn: 'root'
})
export class PokemonsService {
public loadPokemonByQuantity$: BehaviorSubject<any> = new BehaviorSubject(undefined);
constructor(private http: HttpClient) { }
public loadPokemonByQuantity(initial: number, final: number):Observable<any> {
const callArray = [];
const headers = new HttpHeaders({ CACHE_CONTROL: NO_CACHE, PRAGMA: NO_CACHE });
for (let index = initial; index <= final; index++) {
callArray.push(this.http.get<any>(`https://pokeapi.co/api/v2/pokemon/${index}`, { headers }));
}
return Observable.forkJoin(callArray)
}
}
解决方案
使用“rxjs”:“^6.5.2”,像这样使用它:
import { forkJoin } from 'rxjs';
forkJoin(...callArray).subscribe(() => {
// Do something
});
推荐阅读
- pandas - pandas GroupBy agg 计算(传递参数)
- mysql - Mysql-我可以使用 group_concat 和“And”语句来实现这种结果吗
- c# - 打开文件对话框并使用 MediaInfo 库
- node.js - Mongoose,更新对象数组中的每个值
- css - .Less:在变量名中使用 & 和号
- strtol - 测试转换数据类型时的缓冲区问题
- javascript - 显示/隐藏内容列表中的文本
- python - 运行 U-Net 图像分割时出错
- sql - sqlalchemy 如何使用自定义列进行查询,该列给出带有条件的文字
- apache-spark - Spark 结构化流式处理取得进展,但输入行数为 0