angular.copy(source, [destination])
- 作用:对象的深拷贝
- 参数:
- source:源对象
- destination:拷贝的对象
-
返回值:拷贝的对象
<
div
ng-controller
=
"Controller"
>
<
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
>
12345678910111213141516var
app = angular.module(
'myApp'
, []);
app.controller(
'Controller'
, [
'$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();
}]);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/164244.html