i am pulling data using rxjs and my code looks like:
import {Injectable} from '@angular/core';
import {Http, Headers, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class InventoryStatService {
hostEndpoint = 'http://myendpoint';
constructor (public http:Http) {
this.http = http;
}
getInventory() {
return this.http.get(this.hostEndpoint)
.map(res => res.json())
.catch(this.handleError);
}
handleError(error) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}
on invoke side it is:
getStat(){
this.inventoryStatService.getInventory().subscribe(
data => alert("data is:" + JSON.stringify(data))
);
}
at this point getStat() is invoked using a button. however, i want that service gets invoked at some regular interval and update data rather manual call.