I am currently working on implementing an autosave feature in TypeScript. The main objective is to automatically save any text input by the user every 10 seconds to prevent loss of data in case of a page crash or accidental closure. I aim to initiate the autosave functionality immediately after the page has fully loaded.
Here is a snippet of the code I have written:
ngAfterViewInit() {
this.autoSaveContent();
}
private autoSaveContent() {
while (true) {
if (this.isSaving == false && this.hasContentChanged() == true) {
this.content.status = 1;
setTimeout(this.saveContent(), 10000)
}
}
}
I am seeking advice on how to execute the code asynchronously. My intention is for this process to run continuously as soon as the page is accessed, ensuring that the content is consistently saved.