Arithmetic Operations in AngularJs (v1.x)

AngularJS, 55 secs Read, 2 years ago

AngularJs is a library written in JavaScript. It is developed by Google employee, now Google officially supports it. There are many reasons to switch into AngularJS predominantly client side MVC, directive behavior, flexibility. In this tutorial I'm going to show how to perform addition, subtraction, multiplication and division instead of writing hello world program.

A first example: AngularJS

First of create a index.html file and open it with any of your favorite text editor, before you jump into AngularJS application you need to include script source that pointing to AngularJS script.


Just paste the following code into index.html file


Addition: {{ 5 +5 }}

Subtraction: {{ 5 - 5 }}

Multiplication: {{ 5 * 5}}

Division: {{ 5 / 5}}

You might noticed that above HTML code have some extended attributes. Those are AngularJS directives. ng-app directive is like delimiter in many programming languages. Eg: <!--?php ?--> is a PHP delimiter where by PHP compiler parse the code only inside the delimiter, that same way AngularJS uses. Curly braces {{ expression | filter }}, Inside it you can place expression or filter. Once AngularJs compiler found that it will replace curly braces with evaluated value.

This article is outdated.

Quote of the day: live life

Subscribe our Newsletter

Join our mailing list to receive updates on the latest blog posts and other things.