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

docs(angular.copy): add a form example with the 2 possible arguments #4179

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down