Creates a deep copy of source
, which should be an object or an array.
source
is not an object or array, source
is returned.Note: this function is used to augment the Object type in Angular expressions. See
angular.Array
for more information about Angular arrays.
angular.Object.copy(source[, destination]);
source – {*} –
The source that will be used to make a copy.
Can be any type, including primitives, null
, and undefined
.
destination(optional) – {(Object|Array)} –
Destination into which the source is copied. If
provided, must be of the same type as source
.
{*}
– The copy or updated destination
, if destination
was specified.
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>
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'); });