How to refresh and listen to the refreshed data inside one stream

Discussão em 'Angular' iniciado por Mirz, Março 21, 2025.

  1. Mirz

    Mirz Guest

    The important part of my code looks somewhat like this:

    data$:Observable = this.dataRefresh$.pipe(switchMap(() =>
    this.http.get('url')), shareReplay());
    dataRefresh$:Subject = new Subject();

    ngOnInit(){
    this.externalService.getExternalTrigger()
    .pipe(
    // TODO - trigger data refresh and switch to data$
    tap(data => this.doThings(data)))
    .subscribe();
    }

    refresh(){
    this.refreshData$.next();
    }


    I'm trying to get new data after external service notified that the server-side data has been altered. My problem is that I have a few places in an app that need this data so the sharedReplay. When im trying to make some more complicated flow like:

    combineLatest([
    of().pipe(tap(() => this.refresh)),
    this.data.pipe(skipUntil(this.refreshData$))
    ]).pipe(map(([,data]) => data));


    it just gives me circular dependency error. Any ideas?

    Continue reading...

Compartilhe esta Página