I have an Angular 6 project that displays the status of a process that is running on backend server. My first idead was to call the backend API every 2 seconds to refresh the status of the process like this:
My service that communicates with the backend:
getMasterInfo()
{
return this.http.get('http://localhost:8080/pe/info');
}
My component:
onGet() {
this.waitingAgent = "true";
this.waitingMaster = "true";
this.backend.getMasterInfo().subscribe(
(response: Response) => {
this.dataMaster = response.json();
console.log(this.dataMaster.status);
this.waitingMaster = "false";
this.activeMaster = "true";
this.httperrorMaster = "false";
},
(error) => {
console.log("Erro: " + error);
this.waitingMaster = "false";
this.httperrorMaster = "true";
this.activeMaster = "false";
}
);
Maybe using something like .repeat()
, .retry()
or .distinctUntilChanged()
will solve this problem? I don't know how to correctly refresh the status.