angular.copy()
来源:互联网 发布:阿里云域名空间备案 编辑:程序博客网 时间:2024/06/01 12:22
AngularJS API之copy深拷贝
angular提供了一个可以复制对象的api——copy(source,destination),它会对source对象执行深拷贝。
使用时需要注意下面几点:
- 如果只有一个参数(没有指定拷贝的对象),则返回一个拷贝对象
- 如果指定了destination,则会深拷贝对象复制给destination
- 如果source是null或者undefined,那么会直接返回source
- 如果source就是desitination,那么会报错。
下面看看使用样例:
<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="copyExample"> <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= {}; var test1; console.log(angular.copy(test1));//undefined var test3=null; console.log(angular.copy(test2));//undefined var test2 = "a"; // console.log(angular.copy(test2,test2));//error!! $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); console.log($scope.master); console.log($scope.user); }; $scope.reset(); }]); </script></body></html>
0 0
- angular.copy
- angular.copy()
- angular.copy
- angular.copy方法
- angular.copy() 深拷贝
- angular copy深度拷贝
- angular.copy()功能学习
- angular.copy(),angular.extend和angular.merge()方法使用总结
- 日常总结 之 angular copy 深拷贝
- angular中copy和extend用法实例
- 关于angular.copy extend 和merge的理解
- Angular
- angular
- angular
- angular
- angular
- angular
- Angular
- bfs和dfs:poj2386和leetcode130
- linux 使用jrtplib收发h.264视频文件
- 无法打开输入文件“libcaffe.lib” 解决方法
- SpringMVC简单注解实例--简要调用过程
- Angular2源码解读之ChangeDetection
- angular.copy()
- Java RandomAccessFile用法
- vim实现两个文件之间的复制
- Java设计模式《十九》命令模式
- C++派生类的构造函数和析构函数
- Android模拟点击屏幕,实现按键精灵点击屏幕功能
- C/C++内存管理机制
- Codefroces 410 A. Mike and palindrome
- 使用attrs.xml自定义属性