diff options
| author | Uri Goldshtein | 2013-09-27 16:07:54 +0300 | 
|---|---|---|
| committer | Pete Bacon Darwin | 2013-09-30 22:15:57 +0100 | 
| commit | fc05f5e701f77012d54f87facb5a83d56996c7f1 (patch) | |
| tree | 9b6bbccd5515a6ebf46b04f75218b5ac6aafb635 /src | |
| parent | 06a611c4b4cd58f8270f2cd3320f6499ac28629c (diff) | |
| download | angular.js-fc05f5e701f77012d54f87facb5a83d56996c7f1.tar.bz2 | |
docs(angular.copy): add an example with the two possible arguments
Closes #4179
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/src/Angular.js b/src/Angular.js index 740cd691..efb11526 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -609,6 +609,42 @@ function isLeafNode (node) {   * @param {(Object|Array)=} destination Destination into which the source is copied. If   *     provided, must be of the same type as `source`.   * @returns {*} The copy or updated `destination`, if `destination` was specified. + * + * @example + <doc:example> + <doc:source> + <div ng-controller="Controller"> + <form novalidate class="simple-form"> + Name: <input type="text" ng-model="user.name" /><br /> + E-mail: <input type="email" ng-model="user.email" /><br /> + Gender: <input type="radio" ng-model="user.gender" value="male" />male + <input type="radio" ng-model="user.gender" value="female" />female<br /> + <button ng-click="reset()">RESET</button> + <button ng-click="update(user)">SAVE</button> + </form> + <pre>form = {{user | json}}</pre> + <pre>master = {{master | json}}</pre> + </div> + + <script> + function Controller($scope) { +    $scope.master= {}; + +    $scope.update = function(user) { +      // Example with 1 argument +      $scope.master= angular.copy(user); +    }; + +    $scope.reset = function() { +      // Example with 2 arguments +      angular.copy($scope.master, $scope.user); +    }; + +    $scope.reset(); +  } + </script> + </doc:source> + </doc:example>   */  function copy(source, destination){    if (isWindow(source) || isScope(source)) { | 
