所以,我有一個服務,它具有我需要執行的三個功能。
我之所以使用forkJoin,是因為我想在收到所有人的回復后采取進一步行動!其中之一需要接收一個引數。
getDevices(id: string): Observable<IEquipmentRow[]> {
const url = `${apiUrl}/${id}`;
return this.http.get<IGetDevicesResponse>(url)
.pipe(
map(res => {
return res.data;
})
);
}
private regions$ = this.getRegions();
private devices$ = this.getDevices();
public equipmentPreparationData$ = forkJoin({
regions: this.regions$,
devices: this.devices$
});
實作它的最佳方法是什么?也許使用RxJS Subject/ BehaviorSubject?怎么樣RxJS switchMap,我們可以在這里使用它嗎?我是新手RxJS,所以要溫柔:)
uj5u.com熱心網友回復:
嘗試:
// Change your response type
public equipmentPreparationData$(deviceID: string): Observable<any> {
return forkJoin({
regions: this.regions$,
devices: this.getDevices(deviceID)
});
private getDevices(id: string): Observable<IEquipmentRow[]> {
const url = `${apiUrl}/${id}`;
return this.http.get<IGetDevicesResponse>(url)
.pipe(
map(res => {
return res.data;
})
);
}
private regions$ = this.getRegions();
這樣,您可以使用帶引數的函式并傳遞getDevices方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/480851.html
