I want to implement polling in my nativescript with angular application. I want to check for instance each second the state of my backend server. I have this service :
@Injectable()
export class StateService {
getStatus(): Observable<StateApp> {
let headers = this.getHeaders();
return this.http
.get(BackendService.stateUrl, {
headers: headers
})
.map(res => {
return res.json() as StateApp
})
.catch(this.handleErrors);
}
And then I would like to susbscribe to this service and send a request to the server. In my component in my component I have the following code:
IntervalObservable.create(1000).subscribe(() => {
this.statusService.getStatus()
.subscribe(
(next) => {
this.state = next;
};
});
I tried to implement the solution that I read here and that deals with the same issue ( but it's a post from almost 2 years ago) Angular2 http at an interval but for instance when I write IntervalObservable.takeWhile it doesn't exist anymore (rxjs version 5.4.3). So I was wondering what is the way of achieving the same result (i.e first time to not wait one second to obtain the result and to stop sending requests when component is destroyed)