Repeated REST call inside ion page

On the Ionic page, I need to display the qrCode until the rest call to the server returns the ack value. I need to make this call every one or five seconds to check the "activated" phase.

How can I start this repeating call when I enter the page and do it constantly?

+3


source to share


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







All Articles