angular2: how to copy object into another object

后端 未结 8 673
失恋的感觉
失恋的感觉 2021-01-30 10:05

Please help me in order to copy the object into another object using angular 2?

In angular, I used angular.copy() to copy objects to the loose reference of the old object

8条回答
  •  抹茶落季
    2021-01-30 10:29

    Object.assign will only work in single level of object reference.

    To do a copy in any depth use as below:

    let x = {'a':'a','b':{'c':'c'}};
    let y = JSON.parse(JSON.stringify(x));
    

    If want to use any library instead then go with the loadash.js library.

提交回复
热议问题