service.ts:
// Fetch all AgentLog logs using pooling method
getAgentLogStream(): Promise<string> {
const url = `${this.testCaseUrl}/logfile`;
return Observable
.interval(5000)
.flatMap((i)=> this.http.get(url).toPromise().then(response => response.text()).catch(this.handleError));
}
component.ts:
getAgentLogStreamData() {
return this.AgentService.getAgentLogStream()
.subscribe(agentLogStream => this.agentLogStream = agentLogStream, error => console.log(error));
}
Above code snippet demonstrates how I am utilizing a service to handle REST calls and the corresponding component code.
Below is the code within the same component for managing auto-refresh of data:
// Function to auto-refresh the logs
onChange(event) {
console.log('Event', event);
if (event.target.checked) {
this.getAgentLogStreamData();
}
}
I am successfully receiving periodically refreshed data, but facing difficulties in stopping it when navigating to another page. Seeking assistance on how to halt the auto-refresh process when navigating to other pages or toggling through the user interface.