Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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 有人使用过http中rxjs的toPromise和Promise.all吗_Angular_Rxjs6 - Fatal编程技术网

Angular 有人使用过http中rxjs的toPromise和Promise.all吗

Angular 有人使用过http中rxjs的toPromise和Promise.all吗,angular,rxjs6,Angular,Rxjs6,是否有人使用了http中rxjs的来宣传和Promise.all?请给我举个例子。 我如何在带有承诺的组件中检查两个请求是否成功。所有返回一些消息,如API是否成功 getPostAsync(){ 返回此.http.get('https://jsonplaceholder.typicode.com/posts') .pipe(映射((res:Response)=>{return res.json();})) .pipe(catchError((error)=>{return-throwerr(e

是否有人使用了http中rxjs的
来宣传
Promise.all
?请给我举个例子。
我如何在带有
承诺的组件中检查两个请求是否成功。所有
返回一些消息,如API是否成功

getPostAsync(){
返回此.http.get('https://jsonplaceholder.typicode.com/posts')
.pipe(映射((res:Response)=>{return res.json();}))
.pipe(catchError((error)=>{return-throwerr(error);}))
}
getPostAsync1(){
返回此.http.get('https://jsonplaceholder.typicode.com/posts/1')
.pipe(映射((res:Response)=>{return res.json();}))
.pipe(catchError((error)=>{return-throwerr(error);}))
}

您可以对多个请求使用CombineTest


在处理请求时,我不会使用
来宣传
承诺。最好使用观察值和操作符来处理它。我写了一封信。我将使用
forkJoin
来监听两个或更多请求的完成情况,而不是
Promise.all

谢谢。ohhh使用forkJoin很容易。很高兴我能帮上忙。您能将其中一个答案标记为已接受,以便人们知道此问题已得到回答吗?这与forkJoin相同。顺便说一句,我将使用forkJoin。谢谢您的回答
combineLatest(this.http.get('/api'), this.http.get('/api2'))
.subscribe((res: any) => {
    const res = res[0];
    const res2 = res[1];
});