K
K
Konstantin2020-10-31 23:40:50
Angular
Konstantin, 2020-10-31 23:40:50

Why is it calling the Observer method again?

Receive data from the server$events:

this.events$ = this.eventsService.get();
    this.filteredEvents$ = this.createFilter(this.filter$, this.events$).pipe(
      takeUntil(this.onDestroy$),
      catchError((error) => {
        return Observable.throw(error);
      })
    );


Next, I create the this.filteredEvents$

Why filter, when I call the method , the request to the server checkAll()is re-executed :this.eventsService.get();

public checkAll(): void {
    this.filteredEvents$ = this.events$.pipe(
      map((events: IEvent[]) =>
        events.filter(
          (event: IEvent) => (event.checked_export = !event.checked_export)
        )
      )
    );
  }


Subscription in the template:

filteredEvents$ | async

How to avoid that if this.filteredEvents$ is filtered, the method is not called.

The same thing happens when calling:

this.filteredEvents$ = this.events$;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LastDragon, 2020-11-01
@Junart1

https://medium.com/@aksenovdev/hot-vs-cold-observa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question