更新时间:2023-10-08 11:05:28
这可以使用Rxjs库完成
this can be done using Rxjs library
在您的ts文件中
import "rxjs/Rx";
numberSubscription: Subscription;
getLocations(){
console.log("Get them all!");
const data = Observable.interval(10000).startWith(0); <= this is the time interval in ms at which you want check for change of data in database.
this.numberSubscription = data.subscribe((number: number) => {
this.API.getAllLocations().subscribe(result =>{
this.locations = result;
console.log(this.locations);
this.addLocationMarkers();
this.ref.markForCheck();
});
});
}
希望这会有所帮助