forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng.$parse.html
41 lines (40 loc) · 2.59 KB
/
ng.$parse.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
<a href="http://github.com/angular/angular.js/tree/v1.2.3/src/ng/parse.js#L1051" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/parse.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$parse</code>
<div><span class="hint">service in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ng-parse-page"><p>Converts Angular <a href="guide/expression">expression</a> into a function.</p>
<pre class="prettyprint linenums">
var getter = $parse('user.name');
var setter = getter.assign;
var context = {user:{name:'angular'}};
var locals = {user:{name:'local'}};
expect(getter(context)).toEqual('angular');
setter(context, 'newValue');
expect(context.user.name).toEqual('newValue');
expect(getter(context, locals)).toEqual('local');
</pre>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">$parse(expression);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>expression</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="ng-parse-page"><p>String expression to compile.</p>
</div></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-function">function(context, locals)</a></td><td><div class="ng-parse-page"><p>a function which represents the compiled expression:</p>
<ul>
<li><code>context</code> – <code>{object}</code> – an object against which any expressions embedded in the strings
are evaluated against (typically a scope object).</li>
<li><p><code>locals</code> – <code>{object=}</code> – local variables context object, useful for overriding values in
<code>context</code>.</p>
<p>The returned function also has the following properties:</p>
<ul>
<li><code>literal</code> – <code>{boolean}</code> – whether the expression's top-level node is a JavaScript
literal.</li>
<li><code>constant</code> – <code>{boolean}</code> – whether the expression is made entirely of JavaScript
constant literals.</li>
<li><code>assign</code> – <code>{?function(context, value)}</code> – if the expression is assignable, this will be
set to a function to change its value on the given context.</li>
</ul>
</li>
</ul>
</div></td></tr></table></div>
</div>