forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.scope.$set.html
32 lines (31 loc) · 1.28 KB
/
angular.scope.$set.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
<h1>angular.scope.$set</h1>
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
</fieldset>
<h2>Description</h2>
<p>Assigns a value to a property of the current scope specified via <code>property_chain</code>. Unlike in
JavaScript, if there are any <code>undefined</code> intermediary properties, empty objects are created
and assigned in to them instead of throwing an exception.</p><div ng:non-bindable><pre class="brush: js; html-script: true;">
var scope = angular.scope();
expect(scope.person).toEqual(undefined);
scope.$set('person.name', 'misko');
expect(scope.person).toEqual({name:'misko'});
expect(scope.person.name).toEqual('misko');
</pre></div>
<h2>Usage</h2>
<tt ng:non-bindable>
angular.scope.$set(property_chain, value);
</tt>
<h3>Parameters</h3>
<ul>
<li><tt>property_chain</tt> –
<tt>{string}</tt>
<tt></tt>
– String representing name of a scope property. Optionally
properties can be chained with <code>.</code> (dot), e.g. <code>'person.name.first'</code></li>
<li><tt>value</tt> –
<tt>{*}</tt>
<tt></tt>
– Value to assign to the scope property.</li>
</ul>