[email protected]      beta
Donate

Number expressions in AngularJS

Overview: Understanding Number Expressions in AngularJS, What is Number Expressions, AngularJS number expression example, AngularJS binds data to HTML using Expressions.

AngularJS Number Expressions

Number expression as same as the javascript number expression. In short, if any expression using numbers and operators like +,-,/,* (add, subtract, divide, multiply) then those expressions are number expression.

AngularJS example using number expressions.

Example 1 : Here we are going to add two number .i.e 2 + 3 using number expressions. The code looks like as written below.

<div ng-app="">
	<p> Addition of 2 + 3 = {{ 2 + 3 }}</p>
</div>

Same example can also be written using ng-bind directive in angularjs. Final code looks like as writte below.

<div ng-app="">
	<p> Addition of 2 + 3 =  <span ng-bind="2 + 3"></span> </p>
</div>

Output: Addition of 2 + 3 = 5

Try It Yourself ⇒


Example 2 : Here we are going to multiply two number .i.e 2 x 3 using number expressions. The code looks like as written below.

<div ng-app="">
	<p> Multiplication of 10 * 10 = {{ 10 * 10 }}</p>
</div> 

Same example can also be written using ng-bind directive in angularjs. Final code looks like as writte below.

<div ng-app="">
	<p> Multiplication of 10 * 10 =  <span ng-bind="10 * 10"></span> </p>
</div>

Output: Multiplication of 10 * 10 = 100

Try is yourself


Examle 3 Here we are going to calculate an average score from mark-sheet using number expressions. The code looks like as written below.

<div ng-app="" ng-init="minMarks=35;maxMarks=100; marks={physisc:90,chemistry:65,math:75,biology:80}">
Total score {{ marks.physisc + marks.chemistry + marks.math + marks.biology}} out of {{ 4 * maxMarks}}
</div> 

Try is yourself

  Popular Tag
  Recent Posts
  Follow Us
If you find these tutorials helpful then please donate. It will lead me to do more tutorials.
Donate