Angular 5 - equivalent to $interval from AngularJS
You can use interval
with take
to control how many times you want to call your function.
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
const delay = 1000; // every 1 sec
const count = 5; // process it 5 times
Observable.interval(delay).take(count).subscribe(() => {
myFunction(param1, param2);
});
You may make use of the timer
static method and take
operator.
import {timer} from 'rxjs';
import {take} from 'rxjs/operators';
timer(yourDelay, 1000).pipe(
take(yourCount)).subscribe(x=>{
// do here whatever you want to do here
})
I assumed you use RxJS 6.