Improve this Doc  View Source


  1. - function in module ng


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).

Only enumerable properties are taken into account. Non-enumerable properties (both on 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.


angular.copy(source, [destination]);


Param Type Details
source *

The source that will be used to make a copy. Can be any type, including primitives, null, and undefined.


Destination into which the source is copied. If provided, must be of the same type as source.



The copy or updated destination, if destination was specified.


<div ng-controller="ExampleController">
  <form novalidate class="simple-form">
    <label>Name: <input type="text" ng-model="" /></label><br />
    <label>Age:  <input type="number" ng-model="user.age" /></label><br />
    Gender: <label><input type="radio" ng-model="user.gender" value="male" />male</label>
            <label><input type="radio" ng-model="user.gender" value="female" />female</label><br />
    <button ng-click="reset()">RESET</button>
    <button ng-click="update(user)">SAVE</button>
  <pre>form = {{user | json}}</pre>
  <pre>leader = {{leader | json}}</pre>
// Module: copyExample
  module('copyExample', []).
  controller('ExampleController', ['$scope', function($scope) {
    $scope.leader = {};

    $scope.reset = function() {
      // Example with 1 argument
      $scope.user = angular.copy($scope.leader);

    $scope.update = function(user) {
      // Example with 2 arguments
      angular.copy(user, $scope.leader);