0

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.

Vik
  • 8,721
  • 27
  • 83
  • 168

1 Answers1

1

You most likely need to use Rx.Observable.timer or Rx.observable.interval to invoke getInventory() on an interval.

Mark van Straten
  • 9,287
  • 3
  • 38
  • 57