I have multiple methods that contain individual get method but in component How to Call Multiple Rest API and Subscribe in component i.e. calling multiple methods in one subscribe.
get
/** * Get current User from the server. * * @returns {json} current user. */ public getCurrentUser(): any { return this.http.get(this.baseUrl) .pipe(map((res: any) => res.data)); } /** * Get all device statuses from the server. * * @returns {json} all asset statuses. */ public getDeviceConditions(): any { return this.http.get(this.baseUrl) .pipe(map((res: any) => res.data)); }
Suppose the above two methods I want to call withing one subscribe.
To call multiple API parallelly and get a combined response in one short we can use forkJoin method of rxjs. You can do something like this as shown below,
forkJoin([ getCurrentUser(), //observable 1 getDeviceConditions() //observable 2 ]).subscribe(([users, deviceConditions]) => { // When Both are done loading do something });