THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS Expressions


AngularJS ties information to HTML utilizing Expressions.


what is AngularJS

AngularJS articulations can be composed inside twofold supports: {{ expression }}.

AngularJS articulations can likewise be composed inside a mandate: ng-bind="expression".

AngularJS will settle the articulation, and return the outcome precisely where the articulation is written.

AngularJS expressions are much similar to JavaScript expressions: They can contain literals, administrators, and variables.

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

Example

 

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="">
  <p>My first articulation: {{ 5 + 5 }}</p>
</div>

</body>
</html>
Try it »

On the off chance that you expel the ng-app order, HTML will show the articulation for what it's worth, without explaining it:

Example

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div>
  <p>My first articulation: {{ 5 + 5 }}</p>
</div>

</body>
</html>
Try it Yourself »

You can compose articulations wherever you like, AngularJS will essentially resolve the articulation and return the result.

Example: Let AngularJS change the estimation of CSS properties.

Change the shade of the information box underneath, by changing it's value:

Example

<div ng-app="" ng-init="myCol='lightblue'">

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

</div>
Try it Yourself »

AngularJS Numbers

AngularJS numbers resemble JavaScript numbers:

Example

 

<div ng-app="" ng-init="quantity=1;cost=5">

<p>Total in dollar: {{ amount * cost }}</p>

</div>
Try it Yourself »

Same precedent utilizing ng-bind:

Example

<div ng-app="" ng-init="quantity=1;cost=5">

<p>Total in dollar: <span ng-bind="quantity * cost"></span></p>

</div>
Try it Yourself »

AngularJS Strings

AngularJS strings resemble JavaScript strings:

Example

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

<p>The name is {{ firstName + " " + lastName }}</p>

</div>
Try it Yourself »

Same precedent utilizing ng-bind:

Example

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

<p>The name is <span ng-bind="firstName + ' + lastName"></span></p>

</div>
Try it Yourself »

AngularJS Objects

AngularJS objects resemble JavaScript objects:

Example

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

<p>The name is {{ person.lastName }}</p>

</div>
Try it Yourself »

Same model utilizing ng-bind:

Example

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

<p>The name is <span ng-bind="person.lastName"></span></p>

</div>
Try it Yourself »

AngularJS Arrays

AngularJS exhibits resemble JavaScript arrays:

Example

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

<p>The third outcome is {{ points[2] }}</p>

</div>
Try it Yourself »

Same model utilizing ng-bind:

Example

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

<p>The third outcome is <span ng-bind="points[2]"></span></p>

</div>
Try it Yourself »

AngularJS Expressions versus JavaScript Expressions

Like JavaScript articulations, AngularJS articulations can contain literals, administrators, and variables.

Unlike JavaScript articulations, AngularJS articulations can be composed inside HTML.

AngularJS articulations don't bolster conditionals, circles, and special cases, while JavaScript articulations do.

AngularJS articulations bolster channels, while JavaScript articulations do not.