使用RXJS forkjoin时传递参数的最佳方法
因此,我的服务具有三个我需要执行的功能。
我使用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
主题
/crapiorSubject
? rxjs
switchmap
,我们可以在这里使用它吗? 我是新手rxjs
,所以要温柔:)
So, I have a service that has three functions that I need to execute.
I use forkJoin
because I want to take further action when a response has been received for all!
One of them needs to receive one parameter.
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$
});
What is the best way to implement that? Maybe using RxJS
Subject
/BehaviorSubject
?
What about RxJS
switchMap
, can we use it here?
I am new with RxJS
, so be gentle :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
这样,您可以将函数与参数一起使用,并通过
getDevices
方法Try with:
In this way, you can use your function with the parameter and pass through
getDevices
method另外,可能的
解决方案
使用combineLatest
和mergemap
用于传递ID参数:您可以从组件中更改ID参数:
Also, possible
solution
usingcombineLatest
andmergeMap
for passing id parameter:You can change id parameter from component like this: