Answer the question
In order to leave comments, you need to log in
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));
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question