0

In my Ionic 2 project I am downloading data from server every 1 minute in a provider class, and whenever the new data comes I need to refresh a chart in my page class, how can I use observables to achieve that? This is how the code looks like in simplified version:

let startTime = new Date(Math.ceil(new Date().getTime() / 60000) * 60000);
  this.Source = Rx.Observable.timer(startTime, 60000).timeInterval().pluck('interval');

  this.Subscription = this.Source
    .subscribe(data => {

          this.http.post(this.ConnectionString)
            .map(res => res.json())
            .subscribe(data => {
             //code
            });
    });
  • Possible duplicate of [RxJs Observables nested subscriptions?](https://stackoverflow.com/questions/42888604/rxjs-observables-nested-subscriptions) – cartant Aug 09 '17 at 07:41

1 Answers1

0

You can try like this using Observable.interval

//Time in milleseconds 
    Observable.interval(15000).flatMap(x => this.http.post(this.ConnectionString))
      .map(res => res.json())
      .subscribe(data => {
        //code
      });
Sreemat
  • 616
  • 10
  • 28