"Fossies" - the Fresh Open Source Software Archive

Member "angular-1.8.2/docs/partials/api/ng/function/angular.copy.html" (21 Oct 2020, 6956 Bytes) of package /linux/www/angular-1.8.2.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <a href='https://github.com/angular/angular.js/edit/v1.8.x/src/Angular.js?message=docs(angular.copy)%3A%20describe%20your%20change...#L784' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>
    2 
    3 
    4 
    5 <a href='https://github.com/angular/angular.js/tree/v1.8.2/src/Angular.js#L784' class='view-source pull-right btn btn-primary'>
    6   <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
    7 </a>
    8 
    9 
   10 <header class="api-profile-header">
   11   <h1 class="api-profile-header-heading">angular.copy</h1>
   12   <ol class="api-profile-header-structure naked-list step-list">
   13     
   14     <li>
   15       - function in module <a href="api/ng">ng</a>
   16     </li>
   17   </ol>
   18 </header>
   19 
   20 
   21 
   22 
   23 
   24 <div class="api-profile-description">
   25   <h2 id="overview">Overview</h2>
   26   <p>Creates a deep copy of <code>source</code>, which should be an object or an array. This functions is used
   27 internally, mostly in the change-detection code. It is not intended as an all-purpose copy
   28 function, and has several limitations (see below).</p>
   29 <ul>
   30 <li>If no destination is supplied, a copy of the object or array is created.</li>
   31 <li>If a destination is provided, all of its elements (for arrays) or properties (for objects)
   32 are deleted and then all elements/properties from the source are copied to it.</li>
   33 <li>If <code>source</code> is not an object or array (inc. <code>null</code> and <code>undefined</code>), <code>source</code> is returned.</li>
   34 <li>If <code>source</code> is identical to <code>destination</code> an exception will be thrown.</li>
   35 </ul>
   36 <p><br /></p>
   37 <div class="alert alert-warning">
   38   Only enumerable properties are taken into account. Non-enumerable properties (both on <code>source</code>
   39   and on <code>destination</code>) will be ignored.
   40 </div>
   41 
   42 <div class="alert alert-warning">
   43   <code>angular.copy</code> does not check if destination and source are of the same type. It&#39;s the
   44   developer&#39;s responsibility to make sure they are compatible.
   45 </div>
   46 </div>
   47 
   48 
   49 
   50 <h2 id="known-issues">Known Issues</h2>
   51 <div class="known-issue">
   52   <p>This is a non-exhaustive list of object types / features that are not handled correctly by
   53 <code>angular.copy</code>. Note that since this functions is used by the change detection code, this
   54 means binding or watching objects of these types (or that include these types) might not work
   55 correctly.</p>
   56 <ul>
   57 <li><a href="https://developer.mozilla.org/docs/Web/API/File"><code>File</code></a></li>
   58 <li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a></li>
   59 <li><a href="https://developer.mozilla.org/docs/Web/API/ImageData"><code>ImageData</code></a></li>
   60 <li><a href="https://developer.mozilla.org/docs/Web/API/MediaStream"><code>MediaStream</code></a></li>
   61 <li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set"><code>Set</code></a></li>
   62 <li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap"><code>WeakMap</code></a></li>
   63 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get"><code>getter</code></a>/
   64 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set"><code>setter</code></a></li>
   65 </ul>
   66 
   67 </div>
   68 
   69 
   70 <div>
   71   
   72 
   73   
   74 
   75   <h2 id="usage">Usage</h2>
   76     
   77       <p><code>angular.copy(source, [destination]);</code></p>
   78 
   79 
   80     
   81 
   82     
   83 <section class="api-section">
   84   <h3 id="angular.copy-arguments">Arguments</h3>
   85 
   86 <table class="variables-matrix input-arguments">
   87   <thead>
   88     <tr>
   89       <th>Param</th>
   90       <th>Type</th>
   91       <th>Details</th>
   92     </tr>
   93   </thead>
   94   <tbody>
   95     
   96     <tr>
   97       <td>
   98         source
   99         
  100         
  101       </td>
  102       <td>
  103         <a href="" class="label type-hint type-hint-object">*</a>
  104       </td>
  105       <td>
  106         <p>The source that will be used to make a copy. Can be any type, including
  107     primitives, <code>null</code>, and <code>undefined</code>.</p>
  108 
  109         
  110       </td>
  111     </tr>
  112     
  113     <tr>
  114       <td>
  115         destination
  116         
  117         <div><em>(optional)</em></div>
  118       </td>
  119       <td>
  120         <a href="" class="label type-hint type-hint-object">Object</a><a href="" class="label type-hint type-hint-array">Array</a>
  121       </td>
  122       <td>
  123         <p>Destination into which the source is copied. If provided,
  124     must be of the same type as <code>source</code>.</p>
  125 
  126         
  127       </td>
  128     </tr>
  129     
  130   </tbody>
  131 </table>
  132 
  133 </section>
  134     
  135 
  136     <h3 id="angular.copy-returns">Returns</h3>
  137 <table class="variables-matrix return-arguments">
  138   <tr>
  139     <td><a href="" class="label type-hint type-hint-object">*</a></td>
  140     <td><p>The copy or updated <code>destination</code>, if <code>destination</code> was specified.</p>
  141 </td>
  142   </tr>
  143 </table>
  144 
  145   
  146   
  147   
  148 
  149 
  150 
  151   
  152   <h2 id="examples">Example</h2><p>
  153 
  154 <div>
  155   <plnkr-opener example-path="examples/example-angular-copy"></plnkr-opener>
  156 
  157   <div class="runnable-example"
  158       path="examples/example-angular-copy"
  159       module="copyExample"
  160       name="angular-copy">
  161 
  162   
  163     <div class="runnable-example-file" 
  164       name="index.html"
  165       language="html"
  166       type="html">
  167       <pre><code>&lt;div ng-controller=&quot;ExampleController&quot;&gt;&#10;  &lt;form novalidate class=&quot;simple-form&quot;&gt;&#10;    &lt;label&gt;Name: &lt;input type=&quot;text&quot; ng-model=&quot;user.name&quot; /&gt;&lt;/label&gt;&lt;br /&gt;&#10;    &lt;label&gt;Age:  &lt;input type=&quot;number&quot; ng-model=&quot;user.age&quot; /&gt;&lt;/label&gt;&lt;br /&gt;&#10;    Gender: &lt;label&gt;&lt;input type=&quot;radio&quot; ng-model=&quot;user.gender&quot; value=&quot;male&quot; /&gt;male&lt;/label&gt;&#10;            &lt;label&gt;&lt;input type=&quot;radio&quot; ng-model=&quot;user.gender&quot; value=&quot;female&quot; /&gt;female&lt;/label&gt;&lt;br /&gt;&#10;    &lt;button ng-click=&quot;reset()&quot;&gt;RESET&lt;/button&gt;&#10;    &lt;button ng-click=&quot;update(user)&quot;&gt;SAVE&lt;/button&gt;&#10;  &lt;/form&gt;&#10;  &lt;pre&gt;form = {{user | json}}&lt;/pre&gt;&#10;  &lt;pre&gt;leader = {{leader | json}}&lt;/pre&gt;&#10;&lt;/div&gt;</code></pre>
  168     </div>
  169   
  170     <div class="runnable-example-file" 
  171       name="script.js"
  172       language="js"
  173       type="js">
  174       <pre><code>// Module: copyExample&#10;angular.&#10;  module(&#39;copyExample&#39;, []).&#10;  controller(&#39;ExampleController&#39;, [&#39;$scope&#39;, function($scope) {&#10;    $scope.leader = {};&#10;&#10;    $scope.reset = function() {&#10;      // Example with 1 argument&#10;      $scope.user = angular.copy($scope.leader);&#10;    };&#10;&#10;    $scope.update = function(user) {&#10;      // Example with 2 arguments&#10;      angular.copy(user, $scope.leader);&#10;    };&#10;&#10;    $scope.reset();&#10;  }]);</code></pre>
  175     </div>
  176   
  177 
  178     <iframe class="runnable-example-frame" src="examples/example-angular-copy/index.html" name="example-angular-copy"></iframe>
  179   </div>
  180 </div>
  181 
  182 
  183 </p>
  184 
  185 </div>
  186 
  187