Вот простой периодический вызов внутреннего API, просто вызовите метод makePeriodicReq
один раз (например, в ngOnInit
):
import { Subscription, timer } from 'rxjs';
import { switchMap } from 'rxjs/operators';
subscription: Subscription;
makePeriodicReq() {
this.subscription = timer(0, 10000).pipe(
switchMap(() => this.myService.getFromApi())
)
.subscribe(resp => {
console.debug('resp', resp);
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
Обратите внимание, что метод getFromApi
возвращает наблюдаемое.