What's alternative to angular.copy in Angular

后端 未结 15 1188
忘掉有多难
忘掉有多难 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

    Assuming you are using ES6, you can use var copy = Object.assign({}, original). Works in modern browsers; if you need to support older browsers check out this polyfill

    update:

    With TypeScript 2.1+, ES6 shorthand object spread notation is available:

    const copy = { ...original }
    

提交回复
热议问题