Is it possible to use the async
pipe with RxJS
interval()
on dynamically created components, as shown in this example? When applying the async
pipe inside the component, the interval is often ignored when components change.
For instance, if I want to retrieve data every 15 minutes but the components are changing every 15 seconds.
The only solution I've come across is to take data from one Observable
and save it to another, but I'm not sure if this is the best practice. Is there a better way to achieve this?
The structure of the Observable
is:
interval(1000 * 60 * 15).pipe(startWith(0), switchMap(() => this.http.get('someUrl')));
Solution that has worked for me:
interval(1000 * 60 * 15).pipe(startWith(0), switchMap(() => this.http.get('someUrl'))).subscribe((data) => {
this.someUrlData = scheduled([data], asapScheduler);
});