Home >Web Front-end >JS Tutorial >AngularJS API copy deep copy detailed explanation and examples
Angular provides an API that can copy objects - copy(source,destination), which will perform a deep copy of the source object.
You need to pay attention to the following points when using it:
If there is only one parameter (no copied object is specified), a copy object will be returned
If destination is specified , the object will be deeply copied to destination
If source is null or undefined, source
will be returned directly. If source is destination, an error will be reported.
Let’s take a look at the usage example:
<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 class="brush:php;toolbar:false">form = {{user | json}}
master = {{master | json}}