Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fc05f5e

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

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
@@ -609,6 +609,42 @@ function isLeafNode (node) {
609609
* @param {(Object|Array)=} destination Destination into which the source is copied. If
610610
* provided, must be of the same type as `source`.
611611
* @returns {*} The copy or updated `destination`, if `destination` was specified.
612+
*
613+
* @example
614+
<doc:example>
615+
<doc:source>
616+
<div ng-controller="Controller">
617+
<form novalidate class="simple-form">
618+
Name: <input type="text" ng-model="user.name" /><br />
619+
E-mail: <input type="email" ng-model="user.email" /><br />
620+
Gender: <input type="radio" ng-model="user.gender" value="male" />male
621+
<input type="radio" ng-model="user.gender" value="female" />female<br />
622+
<button ng-click="reset()">RESET</button>
623+
<button ng-click="update(user)">SAVE</button>
624+
</form>
625+
<pre>form = {{user | json}}</pre>
626+
<pre>master = {{master | json}}</pre>
627+
</div>
628+
629+
<script>
630+
function Controller($scope) {
631+
$scope.master= {};
632+
633+
$scope.update = function(user) {
634+
// Example with 1 argument
635+
$scope.master= angular.copy(user);
636+
};
637+
638+
$scope.reset = function() {
639+
// Example with 2 arguments
640+
angular.copy($scope.master, $scope.user);
641+
};
642+
643+
$scope.reset();
644+
}
645+
</script>
646+
</doc:source>
647+
</doc:example>
612648
*/
613649
function copy(source, destination){
614650
if (isWindow(source) || isScope(source)) {

0 commit comments

Comments
 (0)