mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-18 11:31:07 +00:00
docs(angular.copy): add an example with the two possible arguments
Closes #4179
This commit is contained in:
parent
06a611c4b4
commit
fc05f5e701
1 changed files with 36 additions and 0 deletions
|
|
@ -609,6 +609,42 @@ function isLeafNode (node) {
|
||||||
* @param {(Object|Array)=} destination Destination into which the source is copied. If
|
* @param {(Object|Array)=} destination Destination into which the source is copied. If
|
||||||
* provided, must be of the same type as `source`.
|
* provided, must be of the same type as `source`.
|
||||||
* @returns {*} The copy or updated `destination`, if `destination` was specified.
|
* @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){
|
function copy(source, destination){
|
||||||
if (isWindow(source) || isScope(source)) {
|
if (isWindow(source) || isScope(source)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue