Hi I have a form in Angular, that i build with values from an Observable from API.
.subscribe((res) => {
this.data = res['attributes'];
});
//this.data is array of objects!!
this.attribs = modifyClean(this.data);
this.attribsOriginal = this.attribs;
Object.freeze(this.attribsOriginal);
After the form is built with this.attribs. If the user edits its original form values and Clicks save, the api saves it. But if the API fails to save (500 error or something) I want the form to go back to its original values. I am not using Reactive forms on purpose. But here is what i am doing when the api fails in error code
,error {
this.attribs = this.attribsOriginal;
}
But this is not replacing the form values with original values. It is retaining the values. I console.log both this.attribs and this.attribsOriginal in error block. Both of them are same values. How is this possible. I froze attribsOriginal. If i say this.attribs = []; the form is completely removed as expected. But why doesnt this.attribs = this.attribsOriginal, replace the form values with orginal values. I thought freezing this.attribsOriginal will have no impact no matter what you do to this.attribs. what can be done to avoid this situation?