What's alternative to angular.copy in Angular

后端 未结 15 1162
忘掉有多难
忘掉有多难 2020-11-29 00:43

How can I copy an object and lose its reference in Angular?

With AngularJS, I can use angular.copy(object), but I\'m getting some error using that in An

15条回答
  •  抹茶落季
    2020-11-29 01:32

    For shallow copying you could use Object.assign which is a ES6 feature

    let x = { name: 'Marek', age: 20 };
    let y = Object.assign({}, x);
    x === y; //false
    

    DO NOT use it for deep cloning

提交回复
热议问题