forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Object.copy.html
55 lines (50 loc) · 2.68 KB
/
angular.Object.copy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<h1>angular.Object.copy</h1>
<div class="angular-object-copy"><h2>Description</h2>
<div class="description"><p>Creates a deep copy of <code>source</code>, which should be an object or an array.</p>
<ul>
<li>If no destination is supplied, a copy of the object or array is created.</li>
<li>If a destination is provided, all of its elements (for array) or properties (for objects)
are deleted and then all elements/properties from the source are copied to it.</li>
<li>If <code>source</code> is not an object or array, <code>source</code> is returned.</li>
</ul>
<p>Note: this function is used to augment the Object type in Angular expressions. See
<a href="#!/api/angular.Array"><code>angular.Array</code></a> for more information about Angular arrays.</p></div>
<h2>Usage</h2>
<div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.Object.copy(source[, destination]);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">source – {*} – </code>
<p>The source that will be used to make a copy.
Can be any type, including primitives, <code>null</code>, and <code>undefined</code>.</p></li>
<li><code ng:non-bindable="">destination<i>(optional)</i> – {(Object|Array)} – </code>
<p>Destination into which the source is copied. If
provided, must be of the same type as <code>source</code>.</p></li>
</ul>
<h3>Returns</h3>
<div class="returns"><code ng:non-bindable="">{*}</code>
– <p>The copy or updated <code>destination</code>, if <code>destination</code> was specified.</p></div>
</div>
<h2>Example</h2>
<div class="example"><doc:example>
<pre class="doc-source">
Salutation: <input type="text" name="master.salutation" value="Hello" /><br/>
Name: <input type="text" name="master.name" value="world"/><br/>
<button ng:click="form = master.$copy()">copy</button>
<hr/>
The master object is <span ng:hide="master.$equals(form)">NOT</span> equal to the form object.
<pre>master={{master}}</pre>
<pre>form={{form}}</pre>
</pre>
<pre class="doc-scenario">
it('should print that initialy the form object is NOT equal to master', function() {
expect(element('.doc-example-live input[name=master.salutation]').val()).toBe('Hello');
expect(element('.doc-example-live input[name=master.name]').val()).toBe('world');
expect(element('.doc-example-live span').css('display')).toBe('inline');
});
it('should make form and master equal when the copy button is clicked', function() {
element('.doc-example-live button').click();
expect(element('.doc-example-live span').css('display')).toBe('none');
});
</pre>
</doc:example></div>
</div>