Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use same model name in different Json array in Angular 2/4

I have two Json arrays like given below.

Items: any[]; Item: any = {};

Both array having same property name ItemName; Items array contains list of item details. If I select one item from Items array and copy to Item. When I update the value from Item it reflects in Items also. How to block this in Angular 2/4

like image 597
Pradees Avatar asked May 01 '26 22:05

Pradees


1 Answers

You need to extract and make a deep clone of your selected item and manipulate it instead of the item in the array. You can do it like this:

Items: any[]; // Your original array
Item: any = {}; // One of the items in the previous array

selectedItem: any = Object.assign({}, Item); // use this item instead of the previous one.

Hope it helps! :)

like image 57
Laiso Avatar answered May 04 '26 04:05

Laiso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!