Angular Expressions

AngularJS Expressions


AngularJS binds information to HTML using Expressions.

AngularJS Expressions

AngularJS expressions tin live written within double braces: {{ expression }}.
AngularJS expressions tin too live written within a directive: ng-bind="expression".
AngularJS volition resolve the expression, in addition to furnish the upshot precisely where the facial expression is written.
AngularJS expressions are much similar JavaScript expressions: They tin incorporate literals, operators, in addition to variables.
Example {{ v + v }} or {{ firstName + " " + lastName }}

Example

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

<div ng-app="">
  <p>My root expression: {{ v + v }}</p>
</div>

</body>
</html>
If you lot take the ng-app directive, HTML volition display the facial expression every bit it is, without solving it:

Example

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

<div>
  <p>My root expression: {{ v + v }}</p>
</div>

</body>
</html>
You tin write expressions wherever you lot like, AngularJS volition just resolve the facial expression in addition to furnish the result.
Example: Let AngularJS alter the value of CSS properties.
Change the color of the input box below, past times changing its value:

Example

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

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

</div>

AngularJS Numbers

AngularJS numbers are similar JavaScript numbers:

Example

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

<p>Total inward dollar: {{ quantity * terms }}</p>

</div>
Same instance using ng-bind:

Example

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

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

</div>
Using ng-init is non rattling common. You volition larn a improve means to initialize information inward the chapter nearly controllers.

AngularJS Strings

AngularJS strings are similar JavaScript strings:

Example

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

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

</div>
Same instance using ng-bind:

Example

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

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

</div>

AngularJS Objects

AngularJS objects are similar JavaScript objects:

Example

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

<p>The get upwards is {{ person.lastName }}</p>

</div>
Same instance using ng-bind:

Example

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

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

</div>

AngularJS Arrays

AngularJS arrays are similar JavaScript arrays:

Example

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

<p>The tertiary upshot is {{ points[2] }}</p>

</div>
Same instance using ng-bind:

Example

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

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

</div>


Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?