angular.copy(source, [destination]);
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| source | * | 被copy的对象. 可以使任意类型, 包括null和undefined. |
| destination (optional) | Object,array | copy去的目的地. 可以省略, 如果不省略, 其必须和source是同类 |
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script>
</head>
<body ng-app="copyApp">
<div ng-controller="CopyController">
<form novalidate class="simple-form">
姓名: <input type="text" ng-model="user.name" /><br />
年龄:<input type="number" ng-model="user.age" /><br />
邮箱: <input type="email" ng-model="user.email" /><br />
性别:<input type="radio" ng-model="user.gender" value="male" /> 男
<input type="radio" ng-model="user.gender" value="female" /> 女
<br />
<button ng-click="reset()">重置</button>
<button ng-click="update(user)">保存(拷贝)</button>
</form>
<pre>form = {{user | json}}</pre>
<pre>master = {{master | json}}</pre>
</div>
<script>
angular.module('copyApp', [])
.controller('CopyController', ['$scope', function($scope) {
$scope.master = {};
$scope.update = function(user) {
$scope.master = angular.copy(user);
console.log($scope.master);
};
$scope.reset = function() {
angular.copy($scope.user, $scope.master);
console.log($scope.master);// Object { }
console.log($scope.user); //undefined
};
$scope.reset();
}]);
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有