angular2:如何将对象复制到另一个对象 [英] angular2: how to copy object into another object

查看:259
本文介绍了angular2:如何将对象复制到另一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,以便使用角度2将对象复制到另一个对象中?

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

在angular中,我使用了angular.copy()将对象复制到旧对象的松散引用中.但是,当我在angular 2中使用相同的代码时,出现以下错误:

In angular, I used angular.copy() to copy objects to the loose reference of the old objects. But, when I used the same in angular 2 getting below error:

错误:角度未定义.

Error: angular is not defined.

推荐答案

解决方案

Angular2是基于诸如TypeScript和ES6之类的现代技术开发的.

Angular2 developed on the ground of modern technologies like TypeScript and ES6.

所以您只需执行let copy = Object.assign({}, myObject).

对象分配-不错例子.

对于嵌套对象: let copy = JSON.parse(JSON.stringify(myObject))

这篇关于angular2:如何将对象复制到另一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆