angular.copy()

<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>angular.copy</title>
</head> <body ng-app="copyExample">
<h1>angular.copy</h1>
<p>
<span>描述:</span><br />
<span>复制一个对象或者数组</span>
</p>
<p>
<span>使用方法:</span><br />
<span>angular.copy(source, [destination])</span>
</p>
<p>
<span>参数:</span><br />
<span>source: 被copy的对象,可以使用任意类型,包括null和undefined</span><br />
<span>destination(optional):Object || array,copy去的目的地可以省略,如果不省略,其必须和source是同类</span><br />
</p>
<p>
<span>返回值:</span><br />
<span>返回这个应用程序的新创建的injector(注入)对象</span>
</p>
<hr />
<div ng-controller="exampleController">
<form novalidate class="siple_form">
姓名:<input type="text" ng-model="user.name"/><br />
邮箱:<input type="email" ng-model="user.email"/>(输入email格式)<br />
性别:<input type="radio" ng-model="user.gender" value="boy"/>男
<input type="radio" ng-model="user.gender" value="girl"/>女<br />
<button ng-click="reset()">reset</button>
<button ng-click="save(user)">save</button>
</form>
<pre>form = {{user | json}}</pre>
<pre>master = {{master | json}}</pre>
</div>
</body>
<script src="../../js/angular.1.3.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
angular.module('copyExample', []).controller('exampleController', ['$scope', function($scope){
$scope.master = {};
$scope.save = function(user){
//console.log('保存')
$scope.master = angular.copy(user)
};
$scope.reset = function(){
//console.log('重置')
angular.copy($scope.master, $scope.user)
}
$scope.reset();
}])
</script> </html>
上一篇:SpringMVC返回json数据的三种方式


下一篇:spring mvc 返回json数据的四种方式