K
K
Konstantin2020-04-26 21:57:41
Angular
Konstantin, 2020-04-26 21:57:41

Why does pipe(share) pull the server twice?

My http service:

@Injectable({
  providedIn: "root",
})
export class HttpService {
  public blocks$: Observable<any>;
  constructor(private http: HttpClient) {
    this.blocks$ = this.http
      .get()
      .pipe(share());
  }
}


In the parent component, I subscribe to receive data:
forkJoin([this.httpService.blocks$]).subscribe(() => {})


And after in the component - the child is subscribed via acync:

*ngFor="let block of httpService.blocks$ | async"

Why do I see two requests together with one in the netfork, why did the share not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semenov, 2020-04-28
@Junart1

And why do you subscribe in the component if you call it in the template via async?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question