angular.copy
来源:互联网 发布:网络策划培训课程 编辑:程序博客网 时间:2024/05/22 02:56
创建一个源文件的深度拷贝,它应该是一个对象或一个数组。
- 如果没有提供目标,则创建一个对象或数组的副本。
- 如果提供了一个目标,那么它的所有元素(对于数组)或属性(对于对象)都会被删除,然后从源文件中复制所有元素/属性。
- 如果源不是对象或数组(包括
null
和undefined
),则返回源。 - 如果源与目标相同,则会抛出异常。
用法
angular.copy(source, [destination]);
参数
null
和 undefined
。 destination(可选) Object Array 源被复制的目标。如果提供,必须与源类型相同。
返回值
如果指定了目标,则返回复制或更新的目标。
举个栗子
HTML:
<div ng-controller="ExampleController"> <form novalidate class="simple-form"> <label>Name: <input type="text" ng-model="user.name" /></label><br /> <label>Age: <input type="number" ng-model="user.age" /></label><br /> Gender: <label><input type="radio" ng-model="user.gender" value="male" />male</label> <label><input type="radio" ng-model="user.gender" value="female" />female</label><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>
JS:
angular.module('copyExample', []).controller('ExampleController', ['$scope', function($scope) { $scope.master = {}; $scope.reset = function() { // Example with 1 argument $scope.user = angular.copy($scope.master); }; $scope.update = function(user) { // Example with 2 arguments angular.copy(user, $scope.master); }; $scope.reset();}]);
阅读全文
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
- ACdream 1077 LCM Challenge (数学题)(LCM)
- iOS搜索框样例
- js中的图片指定切换效果
- 23种设计模式之装饰者模式
- 使用矩阵方式进行文件夹的选择即类似OpenFileDialog
- angular.copy
- gets_s
- python基础之字典dict和集合set
- git常用命令
- Android studio mac版本快捷键
- 泛型(通配符)
- maven 私服搭建
- 多重血条效果
- 混淆遇到无法找到文件aapt_rules.txt