Hey I have a problem with share operator. When I use async pipe with data$ and totalElements$ my http request executes twice. I wish it would execute only once. I tried to use shareReplay istead and It did not work as well.
filters$: BehaviorSubject<any> = ...
...
getComplaints() {
return this.filters$.pipe(
flatMap(filters => {
this.loading = true;
return this.complaintService
.getComplaints$(filters)
.pipe(
finalize(() => this.loading = false),
share()
);
})
);
}
this.data$ = this.getComplaints().pipe(map(value => value.pageItems));
this.totalElements$ = this.getComplaints().pipe(map(value => value.totalItems));