My current project involves implementing form validation, including change detection. I want to display a prompt if a user is editing and tries to navigate away without saving their changes. One challenge I'm encountering is maintaining two arrays with the same initial data but allowing them to diverge as the user makes modifications.
Despite my efforts, I'm struggling to ensure that the second array remains static after being initialized with the data from the first array. Here's the code snippet I've been working on:
this.service.memberData(this.memberId).subscribe(data => {
this.firstArray = data;
if (this.secondArray.length === 0) {
this.secondArray = data;
}
});
How can I ensure that secondArray
retains its initial value without changing once it has been set?