Copy deep copy of AngularJS API

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.