On this page
Improve this Doc View Source angular.copy
- function in module ng
Overview
Creates a deep copy of source, which should be an object or an array. This functions is used internally, mostly in the change-detection code. It is not intended as an all-purpose copy function, and has several limitations (see below).
- If no destination is supplied, a copy of the object or array is created.
- If a destination is provided, all of its elements (for arrays) or properties (for objects) are deleted and then all elements/properties from the source are copied to it.
- If
sourceis not an object or array (inc.nullandundefined),sourceis returned. - If
sourceis identical todestinationan exception will be thrown.
source and on destination) will be ignored.
angular.copy does not check if destination and source are of the same type. It's the developer's responsibility to make sure they are compatible.
Known Issues
This is a non-exhaustive list of object types / features that are not handled correctly by angular.copy. Note that since this functions is used by the change detection code, this means binding or watching objects of these types (or that include these types) might not work correctly.
Usage
angular.copy(source, [destination]);
Arguments
| Param | Type | Details |
|---|---|---|
| source | * |
The source that will be used to make a copy. Can be any type, including primitives, |
| destination
(optional)
|
ObjectArray |
Destination into which the source is copied. If provided, must be of the same type as |
Returns
* |
The copy or updated |
Example
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.
https://code.angularjs.org/1.8.2/docs/api/ng/function/angular.copy