Skip to content

Commit b92c650

Browse files
Urigopetebacondarwin
authored andcommitted
docs(angular.copy): add an example with the two possible arguments
Closes angular#4179
1 parent f7a0f9d commit b92c650

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/Angular.js

+36
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,42 @@ function isLeafNode (node) {
589589
* @param {(Object|Array)=} destination Destination into which the source is copied. If
590590
* provided, must be of the same type as `source`.
591591
* @returns {*} The copy or updated `destination`, if `destination` was specified.
592+
*
593+
* @example
594+
<doc:example>
595+
<doc:source>
596+
<div ng-controller="Controller">
597+
<form novalidate class="simple-form">
598+
Name: <input type="text" ng-model="user.name" /><br />
599+
E-mail: <input type="email" ng-model="user.email" /><br />
600+
Gender: <input type="radio" ng-model="user.gender" value="male" />male
601+
<input type="radio" ng-model="user.gender" value="female" />female<br />
602+
<button ng-click="reset()">RESET</button>
603+
<button ng-click="update(user)">SAVE</button>
604+
</form>
605+
<pre>form = {{user | json}}</pre>
606+
<pre>master = {{master | json}}</pre>
607+
</div>
608+
609+
<script>
610+
function Controller($scope) {
611+
$scope.master= {};
612+
613+
$scope.update = function(user) {
614+
// Example with 1 argument
615+
$scope.master= angular.copy(user);
616+
};
617+
618+
$scope.reset = function() {
619+
// Example with 2 arguments
620+
angular.copy($scope.master, $scope.user);
621+
};
622+
623+
$scope.reset();
624+
}
625+
</script>
626+
</doc:source>
627+
</doc:example>
592628
*/
593629
function copy(source, destination){
594630
if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope");

0 commit comments

Comments
 (0)