$parse

  1. $parseProvider
  2. service in module ng

Converts Angular expression into a function.

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');

Usage

$parse(expression);

Arguments

Param Type Details
expression string

String expression to compile.

Returns

function(context, locals)

a function which represents the compiled expression:

  • context â {object} â an object against which any expressions embedded in the strings are evaluated against (typically a scope object).
  • locals â {object=} â local variables context object, useful for overriding values in context.

    The returned function also has the following properties:

    • literal â {boolean} â whether the expression's top-level node is a JavaScript literal.
    • constant â {boolean} â whether the expression is made entirely of JavaScript constant literals.
    • assign â {?function(context, value)} â if the expression is assignable, this will be set to a function to change its value on the given context.
doc_AngularJS
2016-03-29 16:10:32
Comments
Leave a Comment

Please login to continue.