YouTip LogoYouTip

Angularjs Expressions

# AngularJS Expressions * * * AngularJS uses **expressions** to bind data to HTML. * * * ## AngularJS Expressions AngularJS expressions are written inside double braces: **{{ expression }}**. AngularJS expressions bind data to HTML, which is similar to the **ng-bind** directive. AngularJS will "output" the data where the expression is written. **AngularJS expressions** are very similar to **JavaScript expressions**: they can contain literals, operators, and variables. Example {{ 5 + 5 }} or {{ firstName + " " + lastName }} ## AngularJS Example

My first expression: {{ 5 + 5 }}

[Try it Β»](#) * * * ## AngularJS Numbers AngularJS numbers are like JavaScript numbers: ## AngularJS Example

Total: {{ quantity * cost }}

[Try it Β»](#) The same example using ng-bind: ## AngularJS Example

Total:

[Try it Β»](#) | ![Image 2: Note](#) | Using **ng-init** is not very common. You will learn a better way to initialize data in the Controllers chapter. | | --- | * * * ## AngularJS Strings AngularJS strings are like JavaScript strings: ## AngularJS Example

Name: {{ firstName + " " + lastName }}

[Try it Β»](#) The same example using ng-bind: ## AngularJS Example

Name:

[Try it Β»](#) * * * ## AngularJS Objects AngularJS objects are like JavaScript objects: ## AngularJS Example

The last name is {{ person.lastName }}

[Try it Β»](#) The same example using ng-bind: ## AngularJS Example

The last name is

[Try it Β»](#) * * * ## AngularJS Arrays AngularJS arrays are like JavaScript arrays: ## AngularJS Example

The third value is {{ points }}

[Try it Β»](#) The same example using ng-bind: ## AngularJS Example

The third value is

[Try it Β»](#) * * * ## AngularJS Expressions vs. JavaScript Expressions Similar to JavaScript expressions, AngularJS expressions can contain letters, operators, and variables. Unlike JavaScript expressions, AngularJS expressions can be written in HTML. Unlike JavaScript expressions, AngularJS expressions do not support conditionals, loops, or exceptions. Unlike JavaScript expressions, AngularJS expressions support filters.
← Angularjs DirectivesAngularjs Intro β†’