Read Catalogue
- The following points need to be noted when using:
- Here's a look at the examples:
Angular provides a api--copy (source,destination) that can replicate objects, which performs a deep copy of the source object.
The following points need to be taken into consideration when using the top:
- Returns a Copy object if there is only one parameter (an object with no specified copy)
- If destination is specified, the deep copy object is copied to the destination
- If source is null or undefined, the source is returned directly
- If source is desitination, then it will be an error.
Go back to the top and look at the examples below:
<HTML><Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></Script></Head><BodyNg-app= "Copyexample"> <DivNg-controller= "Examplecontroller"> <formNovalidate class= "Simple-form">Name:<inputtype= "text"Ng-model= "User.Name" /><BR/>e-mail:<inputtype= "Email"Ng-model= "User.email" /><BR/>Gender:<inputtype= "Radio"Ng-model= "User.gender"value= "Male" />male<inputtype= "Radio"Ng-model= "User.gender"value= "female" />female<BR/> <ButtonNg-click= "Reset ()">RESET</Button> <ButtonNg-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= {}; vartest1; Console.log (Angular.copy (test1));//undefined vartest3=NULL; Console.log (Angular.copy (test2));//undefined vartest2= "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 argumentsangular.copy ($scope. master, $scope. User); Console.log ($scope. master); Console.log ($scope. User); }; $scope. Reset (); }]); </Script></Body></HTML>
Copy deep copy of AngularJS API