Repeated REST call inside ion page
1 answer
You can run pinging API onInit ()
ngOnInit(){
this.pingAPI().subscribe(
(data) => {
// activate QR code
}
);
}
private pingAPI(){
return Observable.timer(1000, 5000) // after 1 second, tick every 5 second
.map(() => {
return callAPI().map(
(data) => {
// manipulate data
return data;
}
);
})
// do not go further unless the property 'activationDone' is truthy
.filter(data=> data.activationDone == true)
.first(); // stop the chain when condition satisfies for the first time
}
0
source to share