大佬教程收集整理的这篇文章主要介绍了AngularJS API之copy深拷贝,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
下面看看使用样例:
<!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="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>
以上是大佬教程为你收集整理的AngularJS API之copy深拷贝全部内容,希望文章能够帮你解决AngularJS API之copy深拷贝所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。