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

Commit 6bee655

Browse files
committed
docs(copy): mention ignoring non-enumerable properties
This also improves the example a bit: - better code formatting - initialization of `form` to an empty object - avoid using `email`, which doesn't get coppied when invalid (and might confuse users) Fixes #14853
1 parent acd4551 commit 6bee655

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

src/Angular.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,13 @@ function arrayRemove(array, value) {
752752
* * If a destination is provided, all of its elements (for arrays) or properties (for objects)
753753
* are deleted and then all elements/properties from the source are copied to it.
754754
* * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned.
755-
* * If `source` is identical to 'destination' an exception will be thrown.
755+
* * If `source` is identical to `destination` an exception will be thrown.
756+
*
757+
* <br />
758+
* <div class="alert alert-warning">
759+
* Only enumerable properties are taken into account. Non-enumerable properties (both on `source`
760+
* and on `destination`) will be ignored.
761+
* </div>
756762
*
757763
* @param {*} source The source that will be used to make a copy.
758764
* Can be any type, including primitives, `null`, and `undefined`.
@@ -761,41 +767,42 @@ function arrayRemove(array, value) {
761767
* @returns {*} The copy or updated `destination`, if `destination` was specified.
762768
*
763769
* @example
764-
<example module="copyExample">
765-
<file name="index.html">
766-
<div ng-controller="ExampleController">
767-
<form novalidate class="simple-form">
768-
Name: <input type="text" ng-model="user.name" /><br />
769-
E-mail: <input type="email" ng-model="user.email" /><br />
770-
Gender: <input type="radio" ng-model="user.gender" value="male" />male
771-
<input type="radio" ng-model="user.gender" value="female" />female<br />
772-
<button ng-click="reset()">RESET</button>
773-
<button ng-click="update(user)">SAVE</button>
774-
</form>
775-
<pre>form = {{user | json}}</pre>
776-
<pre>master = {{master | json}}</pre>
777-
</div>
778-
779-
<script>
780-
angular.module('copyExample', [])
781-
.controller('ExampleController', ['$scope', function($scope) {
782-
$scope.master= {};
783-
784-
$scope.update = function(user) {
785-
// Example with 1 argument
786-
$scope.master= angular.copy(user);
787-
};
770+
<example module="copyExample">
771+
<file name="index.html">
772+
<div ng-controller="ExampleController">
773+
<form novalidate class="simple-form">
774+
<label>Name: <input type="text" ng-model="user.name" /></label><br />
775+
<label>Age: <input type="number" ng-model="user.age" /></label><br />
776+
Gender: <label><input type="radio" ng-model="user.gender" value="male" />male</label>
777+
<label><input type="radio" ng-model="user.gender" value="female" />female</label><br />
778+
<button ng-click="reset()">RESET</button>
779+
<button ng-click="update(user)">SAVE</button>
780+
</form>
781+
<pre>form = {{user | json}}</pre>
782+
<pre>master = {{master | json}}</pre>
783+
</div>
784+
</file>
785+
<file name="script.js">
786+
// Module: copyExample
787+
angular.
788+
module('copyExample', []).
789+
controller('ExampleController', ['$scope', function($scope) {
790+
$scope.master = {};
791+
792+
$scope.reset = function() {
793+
// Example with 1 argument
794+
$scope.user = angular.copy($scope.master);
795+
};
788796
789-
$scope.reset = function() {
790-
// Example with 2 arguments
791-
angular.copy($scope.master, $scope.user);
792-
};
797+
$scope.update = function(user) {
798+
// Example with 2 arguments
799+
angular.copy(user, $scope.master);
800+
};
793801
794-
$scope.reset();
795-
}]);
796-
</script>
797-
</file>
798-
</example>
802+
$scope.reset();
803+
}]);
804+
</file>
805+
</example>
799806
*/
800807
function copy(source, destination) {
801808
var stackSource = [];

0 commit comments

Comments
 (0)