[Angular] forkJoin

Dorong·2023년 12월 10일

Angular

목록 보기
6/10
post-thumbnail

✅ forkJoin

  • http요청을 두 번 이상 보내야 하는 데 코드가 복잡하다면
  • 하나로 묶을 수 있는 forkJoin을 활용하쟈
  fetchEvent() {
    forkJoin([
      this.httpService.get<TargetDTO[]>(
        `target/${this.target1ID()}`
      ),
      this.httpService.get<TargetDTO[]>(
        `target/${this.target2ID()}`
      ),
    ]).subscribe({
      next: async ([target1, target2]) => {
        this.target1.set(target1);
        this.target2.set(target2);
      },
    });
  }
profile
AI가 재밌는 풀스택 웹개발자🤖

0개의 댓글