Angularjs expression-expression

Source: Internet
Author: User
Tags filter eval

The following section talks about Angularjs DI (Dependency injection), which describes the ANGULARJS expression expression here. Expression refers to a small fragment of JavaScript code that is typically used for binding (binding) such as: {{expression}}. In Angularjs, it is resolved through the $parse service.

$parse usage: $parse (expression);

Parameters: JavaScript code fragment.

Return value: {function (context, locals)}, result of expression compilation:

Context: An embedded expression executes in scope.

Locals: local variable, often used to replace the rewrite context.

The return value also has the Assign property, allowing for an expression to be assigned a value.

The following expressions will all be valid expressions in Angularjs:

1+2

3*10 | Currency

User.Name

Angularjs-expression vs. JavaScript expressions

The Angularjs view expression is somewhat like a JavaScript expression, but is not performed using the JavaScript expression eval () function, which differs from the JavaScript expression as follows:

All attributes are dependent on the scope action. Not JavaScript's global role in Windows.

The expression evaluates to be compatible with null and undefined, while JavaScript throws a Nullpointerexceptions exception.

No control process statements, conditions, loops throw.

filter, redundant ANGULARJS expression calculation results can be transformed through the filter format, | expressions, such as time, currency, number format.

Note: For angularjs expressions, the $eval () method can be used to parse execution.

Demo

Html:

<!doctype html>    

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.