Podcast/lib/angular/docs/partials/api/ng.$parse.html
2013-09-22 11:21:37 +02:00

41 lines
2.6 KiB
HTML
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a href="http://github.com/angular/angular.js/tree/v1.2.0rc1/src/ng/parse.js#L927" 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="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="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&#39;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>