2017-07-19 17 views
0

私はrxjsを使用してデータを引っ張っていますし、私のコードは次のようになります。呼び出し側にイオン3つの角度rxjs

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'); 
    } 

} 

それは次のようになります。この時点getStat(で

getStat(){ 
    this.inventoryStatService.getInventory().subscribe(
      data => alert("data is:" + JSON.stringify(data)) 
     ); 
    } 

)ボタンを使用して呼び出されます。しかし、私はそのサービスが定期的な間隔で呼び出され、手動ではなくデータを更新したいと思っています。

答えて

関連する問題