Observable関数を呼び出して、10秒ごとにサーバーからデータをダウンロードするにはどうすればよいですか?
私のアプリサービス
getDevices (): Observable<Device[]> {
return this.http.get(this.deviceUrl)
.map(this.extractData)
.catch(this.handleError);
}
私のAppComponent
ngOnInit():void {
this.getData();
this.getLastDeviceInterior();
this.getOutDevice();
this.getSetings();
}
getData()
{
this.dataService.getDevices().subscribe( devices => this.devices = devices,
error => this.errorMessage = <any>error);
}
Angularを使用している場合はsetIntervalを使用できます
getData()
{
setInterval(() => {
this.dataService.getDevices().subscribe( devices => this.devices = devices,
error => this.errorMessage = <any>error);
}, 10);
}
または
setInterval(() => {
this.getData();
}, 10);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加