In my component, I have set up a subscription inside an interval in the onInit method:
ngOnInit() {
interval(5000).pipe(
takeWhile(() => this.isAlive))
.subscribe(() => {
this.initialization();
});
}
initialization() {
this.subscriptions.add(
this.someService.someMethod().subscribe(
data => {
this.myData = Object.assign({}, data);
this.var1 = this.myData.x; // Binding var1 to a text element in HTML
this.var2 = this.myData.y; // Binding var2 to a text element in HTML
}
)
);
}
var1Change(value) {
// Check if my code is in observable, once it completes, execute save immediately. How can I achieve this?
this.var1 = value;
this.myData.x = value;
this.callSave();
}
callSave() {
// Method to consume API and save data to file
}
Every 5 seconds, the UI updates with any changes in the data.
I can edit the data from the UI and automatically save it by consuming the API - the save action only triggers when there's a change in the model without the need for a save button.
What I want is to wait for the save process to complete if my code is within the observable.
Please assist me with the current code structure, as I am required to use interval and Save call in this manner.
Using angular 8.2 and rxjs 6.4