L
L
Lancelot2021-03-05 18:00:58
Angular
Lancelot, 2021-03-05 18:00:58

Does each observable subscription make a request to the server?

Hello. And do not tell me what could be the problem, for some reason each subscription launches a new request to the server? I created 3 subscriptions and here are 3 requests to the server

public getRsp(): Observable<RspInterface[]> {
    const params = new HttpParams()
      .set('app', 'cabinet')
      .set('limit', '100')
      .set('offset', '0')
      .set('searchString', 'eee');

    return this.http.get<RspResponseInterface>(`${baseUrl}getRsp`, { params })
      .pipe(
        filter((data: RspResponseInterface) => data.success),
        map((data: RspResponseInterface) => data.data),
        catchError(this.handleError)
      );
  }

.....

  ngOnInit(): void {
    this.rsp$ = this.apiCatalogService.getRsp();
    this.rsp$.subscribe(rsp => this.rsp = rsp);
    this.rsp$.subscribe(rsp => console.log(1));
    this.rsp$.subscribe(rsp => console.log(2));
  }


60424791af668023953086.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
display: block, 2021-03-05
@qork

All observables returned from HttpClient methods are cold by design.
https://angular.io/guide/http#always-subscribe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question