?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
創(chuàng)建source
的深度復制,可以為一個對象或一個數(shù)組。
source
不是一個對象或數(shù)組(包括null
和undefined
),返回source
。source
等于'destination',將拋出一個錯誤。angular.copy(source, [destination]);
參數(shù) | 類型 | 詳述 |
---|---|---|
source | * | 用于復制的源??梢詾槿魏晤愋停ɑA類型、 |
destination
(可選)
|
ObjectArray | 存儲復制后的目標。如果提供,必須和 |
* | 副本或更新后的 |
<div ng-controller="ExampleController">
<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>
angular.module('copyExample')
.controller('ExampleController', ['$scope', Function($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>