I am currently developing an Angular 2 application using TypeScript. In a User Management component, I have implemented a table that displays all the users in my system.
When a user is clicked on within the table, a form appears with their complete set of properties for editing. The selection of a user triggers the following event:
onUserSelected(event) {
var selectedId = event.data.id;
this.selectedUser = this.users.filter(user => user.id === selectedId)[0]
}
However, I encountered an issue where when the selectedUser is edited, the changes reflect directly in the table as well, which is not ideal from a user experience standpoint. My attempt to create a copy of the user by implementing a clone function did not resolve the issue - see code below:
clone() {
var cloned = new User(this.id, this.login, this.name, this.surname, this.phone);
return cloned;
}
It seems like there might be a better way to handle this situation in Angular 2. Any suggestions or recommendations would be greatly appreciated.