View source Improve this doc

$parse

service in module ng

Description

Converts Angular expression into a function.

  1. var getter = $parse('user.name');
  2. var setter = getter.assign;
  3. var context = {user:{name:'angular'}};
  4. var locals = {user:{name:'local'}};
  5.  
  6. expect(getter(context)).toEqual('angular');
  7. setter(context, 'newValue');
  8. expect(context.user.name).toEqual('newValue');
  9. expect(getter(context, locals)).toEqual('local');

Usage

  1. $parse(expression);

Parameters

ParamTypeDetails
expressionstring 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.