AngularJS: API: ng/service/$parse


  1. - $parseProvider
  2. - service in module ng

Converts Angular expression into a function.

  var getter = $parse('');
  var setter = getter.assign;
  var context = {user:{name:'angular'}};
  var locals = {user:{name:'local'}};

  setter(context, 'newValue');
  expect(getter(context, locals)).toEqual('local');




Param Type Details
expression string

String expression to compile.


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.