AngularJS Tutorial

Toggle navigation
TUTORIAL HOME
AngularJS Tutorial
❮ Home Next ❯

AngularJS extends HTML with new attributes.

AngularJS is perfect for Single Page Applications (SPAs).

AngularJS is easy to learn.

Learn AngularJS now!
This Tutorial
This tutorial is specially designed to help you learn AngularJS as quickly and efficiently as possible.

First, you will learn the basics of AngularJS: directives, expressions, filters, modules, and controllers.

Then you will learn everything else you need to know about AngularJS:

Events, DOM, Forms, Input, Validation, Http, and more.

Examples in Every Chapter
In every chapter, you can edit the examples online, and click on a button to view the result.

AngularJS Example

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js“>

 

Name :

 

Hello {{name}}

»
What You Should Already Know
Before you study AngularJS, you should have a basic understanding of:

HTML
CSS
JavaScript
AngularJS History
AngularJS version 1.0 was released in 2012.

Miško Hevery, a Google employee, started to work with AngularJS in 2009.

The idea turned out very well, and the project is now officially supported by Google.

AngularJS Examples
Omegas’ AngularJS tutorial contains lots of AngularJS examples!

AngularJS Examples

AngularJS Reference
The AngularJS reference contains all directives and filters used in this tutorial.

AngularJS Reference

❮ Home Next ❯

AngularJS Expressions

Toggle navigation
TUTORIAL HOME
AngularJS Expressions
❮ Previous Next ❯
AngularJS binds data to HTML using Expressions.

AngularJS Expressions
AngularJS expressions can be written inside double braces: {{ expression }}.

AngularJS expressions can also be written inside a directive: ng-bind=”expression”.

AngularJS will resolve the expression, and return the result exactly where the expression is written.

AngularJS expressions are much like JavaScript expressions: They can contain literals, operators, and variables.

Example {{ 5 + 5 }} or {{ firstName + ” ” + lastName }}

Example

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js“>

 

My first expression: {{ 5 + 5 }}

»
If you remove the ng-app directive, HTML will display the expression as it is, without solving it:

Example

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js“>

 

My first expression: {{ 5 + 5 }}

»
You can write expressions wherever you like, AngularJS will simply resolve the expression and return the result.

Example: Let AngularJS change the value of CSS properties.

Change the color of the input box below, by changing its value:


{{myCol}}
Example

<input style="background-color:{{myCol}}” ng-model=”myCol” value=”{{myCol}}”>

»
AngularJS Numbers
AngularJS numbers are like JavaScript numbers:

Example

Total in dollar: {{ quantity * cost }}

»
Same example using ng-bind:

Example

Total in dollar:

»
Using ng-init is not very common. You will learn a better way to initialize data in the chapter about controllers.

AngularJS Strings
AngularJS strings are like JavaScript strings:

Example
<div ng-app="" ng-init="firstName='John';lastName=’Doe'”>

The name is {{ firstName + ” ” + lastName }}

»
Same example using ng-bind:

Example
<div ng-app="" ng-init="firstName='John';lastName=’Doe'”>

The name is

»
AngularJS Objects
AngularJS objects are like JavaScript objects:

Example
<div ng-app="" ng-init="person={firstName:'John’,lastName:’Doe’}”>

The name is {{ person.lastName }}

»
Same example using ng-bind:

Example
<div ng-app="" ng-init="person={firstName:'John’,lastName:’Doe’}”>

The name is </span>

»
AngularJS Arrays
AngularJS arrays are like JavaScript arrays:

Example
<div ng-app="" ng-init="points=[1,15,19,2,40]”>

The third result is {{ points[2] }}

»
Same example using ng-bind:

Example
<div ng-app="" ng-init="points=[1,15,19,2,40]”>

The third result is </p>

»
AngularJS Expressions vs. JavaScript Expressions
Like JavaScript expressions, AngularJS expressions can contain literals, operators, and variables.

Unlike JavaScript expressions, AngularJS expressions can be written inside HTML.

AngularJS expressions do not support conditionals, loops, and exceptions, while JavaScript expressions do.

AngularJS expressions support filters, while JavaScript expressions do not.

Learn about JavaScript in our JavaScript Tutorial.

❮ Previous Next ❯