does anyone have used toPromise and Promise.all from rxjs in http

Indraraj26

Has anyone used toPromise and Promise.all from rxjs in http? Please give me an example.
How can I check both of the request is success in component with promise.all return some message like API is success?

getPostAsync() {
    return this.http.get('https://jsonplaceholder.typicode.com/posts')
                    .pipe(map((res:Response) => { return res.json();}))
                    .pipe(catchError((error) => { return throwError(error);}))
}
getPostAsync1() {
    return this.http.get('https://jsonplaceholder.typicode.com/posts/1')
                    .pipe(map((res:Response) => { return res.json();}))
                    .pipe(catchError((error) => { return throwError(error);}))
}
Dzhavat Ushev

I wouldn't use toPromise nor Promise.all when handling requests. It's better to handle it using observables and operators. I've written an article about replacing Promises with RxJS. Instead of Promise.all, I'd use forkJoin to listen for the completion of two or more requests.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Does anyone have experience recovering the files from a Promise NS4300 server disk?

Angular/rxjs: Why don't I have to import toPromise anymore?

Promise .all() with RxJS

http provider Observable.toPromise() not working as expected in promise chains

.toPromise() and lastValueFrom() in rxjs

Rxjs toPromise() deprecated

RxJS catchError operator does not catch an error on an observable created from a Promise

RxJs equivalent of Promise.all()

Does redirect from HTTP to HTTPS have encryption?

Anyone have syntax for removing all components at once from COM+ Application using Powershell

Does anyone have a useful mnemonic for implementing Comparator?

Does anyone have any experiences with Eclipse GMF?

Does anyone have a sample GWT 2.7.0 pom?

Does anyone have a List of hive error codes?

Does anyone have the AllJoyn On to make it available to me?

Angular Http - toPromise or subscribe

Does anyone have an example to store crawl data from scrapy to MySQLdb using Peewee?

Does anyone have any idea how I might extract an id from the current url with Meteor and Iron Router?

Large Dataframe from a url has a very strange format. Does anyone have any advice on how to reformat?

RxJs expand array from promise

returned results from promise.all() does not capture scoped variable

Promise.all behavior with RxJS Observables?

Angular rxjs: method does not wait for promise to finish

Does anyone know the unit of scale used in scale parameter in ViewPointCenter?

RxJS .toPromise returns only one value

How to merge or groupBy toPromise via RxJs?

Has no exported member 'toPromise' rxjs- 5.5.2

How to handle .toPromise() deprecation with RXJS and Angular 13

Does this method from the JDK make sense to anyone?