wonderfan / javascript

Explore the power of HTML,CSS and JavaScript
1 stars 0 forks source link

Parse service in AngularJS #103

Closed wonderfan closed 8 years ago

wonderfan commented 8 years ago

The $parse compiles an expression to a function which can be then invoked with a context and locals in order to retrieve the expression’s value.

wonderfan commented 8 years ago

The first parameter is context – this is an object any expressions embedded in the strings are evaluated against (typically a scope object). The second parameter is locals – this is an JavaScript object with local variables, useful for overriding values in context.

wonderfan commented 8 years ago

It is important to understand that $parse can be invoked once and its result (pre-compiled expression) can be used multiple times with different context (and locals).

wonderfan commented 8 years ago

$eval is a method on a scope. It executes an expression on the current scope and returns the result.

wonderfan commented 8 years ago

$interpolate. By means of $interpolate you can do on-the-fly templating like well-known template engines Handlebars or Hogan do that.

wonderfan commented 8 years ago

The source code: https://github.com/angular/angular.js/blob/master/src/ng/parse.js