所以,我有一个服务,它有三个我需要执行的功能.

我使用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

推荐答案

try 使用:

// 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方法传递

Angular相关问答推荐

Angular 17自定义指令渲染不起作用'

尾风手风琴中的Ngor

如何在Angular中执行一个操作条件为多个可观测值?

PrimeNG面包屑组件生成奇怪的&

仅在展示时使用垫式步进器

茉莉花-模板中调用了如何判断角管

成Angular 的嵌套router-outlet

角路径S异步旋转变压器仍可观察到

Primeng:安装ANGLE 16.2.0版本

Ng serve不工作,没有错误或消息来显示问题所在

使用forkJoin和mergeMap的正确方式是什么?

以 Angular 形式添加动态控件失败

在父组件的子组件中使用 ng-template

Angular SPA 和 .Net 6 API 之间未连接 Application Insights Map

由router-outlet 创建时如何将css类应用于组件元素?

如何在 Angular 2 中正确设置 Http 请求标头

@angular/platform-b​​rowser 与 @angular/platform-b​​rowser-dynamic

如何在 Angular 2 中动态添加和删除表单字段

如何作为模块的子模块路由到模块 - Angular 2 RC 5

如何在 Angular CLI 6: angular.json 中添加 Sass 编译?