日常总结 之 angular copy 深拷贝
2015-12-14 10:32
627 查看
angular提供了一个可以复制对象的api——copy(source,destination),它会对source对象执行深拷贝。
angular的操作实质是对dom的model进行操作,几乎所有的渲染都应放在model层。
angular的操作实质是对dom的model进行操作,几乎所有的渲染都应放在model层。
<html ng-app="myApp"> <head> <meta charset='utf-8'> <script src="./angular.min.js"></script> </head> <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> <script> var 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.user);//重置数据的层面放在此处,此处将一个空对象{}深拷贝到user中,可以根据需求放入原来的模型。 }; $scope.reset(); }]); </script> </html>
相关文章推荐
- 基于mac系统的apache服务器的使用流程
- Linux开机报"write same failed manually zeroing"错误
- 网站访问量大 怎样优化mysql数据库
- 如何使用 pv 命令监控 linux 命令的执行进度
- xcode 删除sourceControl中多余的workingCopies
- nc在centos7上的安装和简单使用
- tomcat 线程数相关问题
- .公司域名总量TOP15:易名升至第十二 涨幅最大
- 升级10.11后使用CocoaPod出现-bash: pod: command not found 解决办法
- linux命令之tee
- 3.LINUX后台进程与前台进程的区别
- 每天一个linux命令--awk
- Hadoop MapReduce处理海量小文件:基于CombineFileInputFormat(整个小文件读入到map中)
- java.lang.NullPointerException at org.apache.jsp.**_jsp.jspInit(index_jsp.java)异常 解决方案
- tomcat内存溢出
- Linux下yum订购具体解释
- 【Nginx】nginx为目录或网站加上密码认证
- linux归档文件,归档目录
- 每天一个linux命令--退出<符号
- splinter 学习笔记