Monday, 18 September 2017

angular - Cloning objects TypeScript

I am working with Angular 2 with TypeScript. I have User Management component where I have table of whole users.



When any user in table is clicked then forms appeaer with his whole properties to edit. Choosing user occurs event as below:



 onUserSelected(event) {
var selectedId = event.data.id;
this.selectedUser = this.users.filter(user => user.id === selectedId)[0]
}



The problem is when selectedUser is being edited his properties also changes in table and it doesnt look so good. I tried to create copy myself as below but it didn't help - user class



 clone() {
var cloned = new User(this.id, this.login, this.name, this.surname, this.phone);
return cloned;
}


Maybe I am doing something which is not good practice in Angular2?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...