1
I am currently doing a project and I need to get information from the bank that is updated and for this I am giving a get every 5 seconds using setInterval. But I know this isn’t the best of worlds, so I’d like to know what to do.
I’ve heard about Subscription or something, but I have no idea how to implement.
import { ApiService } from 'src/app/core/services/api.service';
ngOnInit() {
this.getFiles();
this.interval = setInterval(() => {
this.getFiles();
}, 5000);
}
getFiles() {
const files = this.apiService.getFiles().subscribe(data => {
return data['response'];
}, error => {
console.log(error);
});
}
But you can not update only if there is change? Because this way it will continue to request every 5s neh?
– Lucas Brito
But update that, not made clear in the question??
– LeAndrade
You’re right. But the update is related to the value of the files variable.
– Lucas Brito