This article introduces the basics of Angularjs. I collected the following information from various web resources and have attempted to explain them in an easy way.
- Angularjs is a JavaScript MVC framework created by Google to build properly architectured and maintainable web applications
- It decreases emphasis on directly handling DOM manipulation from the application logic
- It employs efficient two-way data binding and sensible MVC implementation
- We can create our own HTML custom tags and attributes
- We need to download the Angularjs from the following link.
Angularjs
- Angularjs revolves around Model, View and Controller
- Using Angularjs we can eliminate the use of document.getelemetbyid('..') and so on.
Before proceeding I am assuming we are familair with the MVC framework.
To understand MVC we can go to the following:
ASP.NET MVC Overview
We will learn the following things in AngularJs:
- Directives
- Expressions
- $scope object
- Controllers
- Model
- Module
- Filters
- Data binding
1. Directives
Directives can be used to create custom HTML tags that serve new, custom widgets. They can also be used to "decorate" elements with behavior and manipulate DOM attributes in interesting ways. HTML consists of static pages but we can now use extended HTML that provides dynamic features by adding attributes, element and comments.
We generally have directives starting with "ng-".
We need to add a directive to an existing HTML form using "np-app" as in the following:
<html ng-app>
We have the following directives:
- ng-app
This will activate the AngularJS to the entire document
We need to add to a HTML form like this: <html ng-app>
- ng-model
This links the model and the form. This means that any changes to the control update the data in our model and when we update the model it updates the control. We can define the model as in the following:
<input ng-model="modeltest">
- ng-controllers
In Angular, a Controller is a JavaScript constructor function that is used to augment the Angular Scope as in the following:
<div ng-controller="modeltest">
Here we need to define the controller with the name "modeltest" in a separate JavaScript file. Other directives are the following:
- ng-click
- ng-repeat
- ng-view
- ng-bind
We have various ways to define a directive and all of the following have the same meaning:
- <input ng-model="modeltest">
- <input data-ng:model=" modeltest ">
- <input ng:model=" modeltest ">
- <input ng_model=" modeltest ">
2. Expressions
- The {{ }} are a declarative way of specifying a data binding location in HTML. AngularJS will automatically update this text.
- Using an expression we can do data binding, as in {{ }}.
Expression example

Output of the above HTML
The following output will be will be rendered in the DOM:
1+2=3
3. Let's start with a sample example.
HTML file
- <html ng-app>
- <head>
- <script src="script/angular.min.js"></script>
- </head>
- <body>
- <div>
- <input type="text" ng-model="uservalue" placeholder="enter text here">
- <h1>
- Hello, {{ uservalue }}</h1>
- </div>
- </body>
- </html>
- ng-model: is a model directive that can be bi-directional. Here the model name is the uservalue
- {{ uservalue }} : {{ }} are expressions in Angularjs and the uservalue inside the {{ }} is to be displayed on the HTML form.
- The following is the output of the HTML code above.
HTML output

4. Angular Module
An Angular module is simply a collection of functions defined in a JavaScript file.
How to define a module in angularjs:
- First create sample.js
- Inside the sample.js file we need to add the following line:
var app = angular.module('myApp', []);
This line creates the Angular module named "myApp".
- We need to define this module in our DOM, the module name is "myApp"
- <html ng-app="myApp">
5. Controllers
In Angular, a Controller is a JavaScript constructor function that augments the Angular Scope.
We have code below in the table, the left column contains HTML code and the right column contains Sample.js. Here we are defining MyUserController in Sample.js. We can define a controller in HTML form using the "ng-controller" directive.
HTML file
- <html ng-app>
- <head>
- <script src="angular.min.js"></script>
- <script src="sample.js"></script>
- </head>
- <body>
- <div ng-controller="MyUserController">
- Your name:
- <input type="text" ng-model="name">
- <button ng-click='sayHello()'>
- greet</button>
- <hr>
- {{greeting}}
- </div>
- </body>
- </html>
- function MyUserController ($scope) {
- $scope.name = 'World';
- $scope.sayHello = function() {
- $scope.greeting = 'Hello ' + $scope.name + '!';
- };
- }
6. $scope object
- Scope is the glue between an application controller and the view.
- A $scope is an object that ties a view (a DOM element) to the controller.
- In the Model-View-Controller structure, this $scope object becomes the model.
- The $scope is just a JavaScript object. Both the controller and the view have access to the $scope so it can be used for communication between the two.

7. Returning to point 5
The following is the screen that will be rendered on the DOM.

The following is the description of the example above:
- From the left column we are getting "World" in the text box, only due to the $scope binding done by the controller $scope.name = 'World' of the controller and ng-model="name" of the DOM.
(This is what we can say one way binding)
- From the right column, here I typed in some text and then clicked on the greet button and I get "Hello World....Binding test!" by the DOM. It is due to declaring {{ greeting }} by the DOM (it is an expression) and the $scope.greeting = 'Hello ' + $scope.name + '!' at MyUserController function.
- Here we have two-way binding using $scope.name and ng-model="name" defined in the DOM and the Controller as well. We got a default value in the text box when the DOM is loaded and are getting the updated value of username when we click on the button.
8. Filters in Angular
Filters allow formatting the data to be displayed on the DOM. Filters are invoked in the HTML with the | (pipe) character inside expressions {{ }}.
|
Filter |
Filter with Expression |
Output at DOM |
| Currency | {{ 123 | currency }} | $123.00 |
| Currency | {{ 456 | currency:'USD $' }} | USD $456.00 |
| Date | {{ today | date:'MMM d, y' }} | Nov 20, 2013 |
| Number | {{ 1234567890 | number }} | 1,234,567,890 |
| Uppercase | {{ "csharp" | uppercase }} | CSHARP |
| String | {{ ['Ari', 'Likes', 'To'] | filter:'e' }} | Likes |
References

Murugan PerumalPosted Aug 5, 2017, 3:05 AM
Very nice , useful article and easy to understand, Thank you Sibeesh Venu
Jothimani ElumalaiPosted Jul 17, 2017, 6:26 AM
Wow nice article ... very useful for to start my article and education purpose.... Thank you...
Vijay NimkardePosted Jun 15, 2017, 12:14 AM
Its great. Suggestion :make changes in above example. That example should be doller to INR. because 1 $ =62 INR. or you can divide by 62 it instead of multiplication.
Suneel Kumar BiyyapuPosted May 31, 2017, 9:58 AM
Great article Sibeesh Venu . Keep posting new articles.
Vinathi VinniPosted May 17, 2017, 6:23 AM
Nick article mr.sibeesh
Sibeesh VenuPosted Sep 20, 2016, 6:24 AM
Satish Kumar Vadlavalli Thanks much
Satish Kumar VadlavalliPosted Sep 20, 2016, 5:17 AM
Good
Sibeesh VenuPosted Jul 6, 2016, 7:43 AM
Debasis Saha Thanks
Debasis SahaPosted Jul 6, 2016, 7:15 AM
Good One..
Sibeesh VenuPosted Jul 6, 2016, 6:30 AM
kalu singh rao Thanks
Sibeesh VenuPosted Jul 6, 2016, 6:29 AM
Rajeev Punhani Thanks
Sibeesh VenuPosted Jul 6, 2016, 6:29 AM
Sr Karthiga Thanks
kalu singh raoPosted Jul 6, 2016, 6:21 AM
Nice...
Rajeev PunhaniPosted Mar 28, 2016, 7:59 AM
Very nicely explained.
Sr KarthigaPosted Feb 23, 2016, 7:46 PM
good one
Sr KarthigaPosted Feb 23, 2016, 7:46 PM
Nice explanation
Sibeesh VenuPosted Dec 21, 2015, 1:33 AM
saranya rajendran Thank you
Saranya RajendranPosted Dec 21, 2015, 1:30 AM
really helpful..
Sibeesh VenuPosted Oct 14, 2015, 4:50 AM
Nagaraj S Thanks a lot for your kind words
Nagaraj SPosted Oct 14, 2015, 2:20 AM
Hi Sibeesh! Very well explained. The way you have illustrated is simple and beautiful. Look forward to your future articles.
Sibeesh VenuPosted Oct 7, 2015, 10:32 AM
Bhavana K thank you so much :)
Bhavana KyPosted Oct 7, 2015, 10:27 AM
Excellent Sibeesh !! Desperately waiting for ur next updates on Angular js
Sibeesh VenuPosted Jul 8, 2015, 12:20 AM
sujit kumar Thank you :)
sujit kumarPosted Jul 7, 2015, 1:28 PM
This is good learning stuff.... Thank you
Sibeesh VenuPosted Jun 22, 2015, 8:45 AM
Jacob Robinson Thank you :)
Jacob RobinsonPosted Jun 22, 2015, 3:45 AM
Nice Article..
Sibeesh VenuPosted Jun 19, 2015, 5:45 AM
Abhishek Tiwari Thank you
Abhishek TiwariPosted Jun 19, 2015, 5:16 AM
Nice Articles
Sibeesh VenuPosted Jun 17, 2015, 2:53 AM
Atul Gupta Thank you :)
Atul GuptaPosted Jun 17, 2015, 1:26 AM
Informative, Thanks for sharing Knowlegde!
Sibeesh VenuPosted Jun 16, 2015, 8:34 AM
Prasham Sabadra Thank you:)
Sibeesh VenuPosted Jun 16, 2015, 8:34 AM
Nitin Tyagi Thank you:)
Sibeesh VenuPosted Jun 16, 2015, 8:34 AM
Pankaj Kumar Choudhary Thank you:)
Sibeesh VenuPosted Jun 16, 2015, 8:33 AM
Sathish Kumar Thank you:)
Prasham SabadraPosted Jun 16, 2015, 8:18 AM
Thanks for sharing :)
NitinPosted Jun 16, 2015, 8:05 AM
nice
Pankaj Kumar ChoudharyPosted Jun 16, 2015, 7:59 AM
Nice Artcile Sir...........
Sathish KumarPosted Jun 16, 2015, 7:48 AM
Really wonderful way of explaining the concepts, great work. Keep rocking sibeesh.
Sibeesh VenuPosted Jun 16, 2015, 7:09 AM
Gopi Chand Thank you :)
Gopi ChandPosted Jun 16, 2015, 6:37 AM
Great work done...
Sibeesh VenuPosted Jun 16, 2015, 6:23 AM
Rakesh Chavda Thank you
Sibeesh VenuPosted Jun 16, 2015, 6:23 AM
Manoj Kulkarni Thank you
Sibeesh VenuPosted Jun 16, 2015, 6:23 AM
subrata sarkar Thank you
Sibeesh VenuPosted Jun 16, 2015, 6:23 AM
Debasis Saha Thank you
RakeshPosted Jun 16, 2015, 6:05 AM
Good one
Manoj KulkarniPosted Jun 16, 2015, 5:55 AM
Nice article. Thank you for sharing
Debasis SahaPosted Jun 16, 2015, 5:23 AM
Nice Article
subrata sarkarPosted Jun 3, 2015, 7:02 PM
nice one. I think u missed the <div ng-app="angularBasic" ng-controller="InrToDollar"> in ng-controller - it is there in the complete example though
Sibeesh VenuPosted Jun 3, 2015, 5:34 AM
Rahul Saxena Thanks buddy http://sibeeshpassion.com/microsoft-asp-net-article-of-the-day-3-jun-2015/
Rahul Kumar SaxenaPosted Jun 3, 2015, 5:22 AM
congrats Article of the day bro...
Vishwakant TripathiPosted Apr 24, 2015, 10:16 AM
nice..
Sibeesh VenuPosted Apr 15, 2015, 1:21 AM
Saineshwar Bageri Thanks dude.
Sibeesh VenuPosted Apr 15, 2015, 1:20 AM
Sanjay singh Thanks buddy.
Saineshwar BageriPosted Apr 15, 2015, 1:18 AM
nice one sibu
Sanjay SinghPosted Apr 15, 2015, 12:12 AM
good one
Sibeesh VenuPosted Apr 14, 2015, 11:25 PM
Rahul Saxena Thank you buddy.
Rahul Kumar SaxenaPosted Apr 14, 2015, 10:52 PM
Good Show bro...
Sibeesh VenuPosted Apr 14, 2015, 10:21 AM
Abhishek Jaiswal Thanks mate. Glad you liked it.
Sibeesh VenuPosted Apr 14, 2015, 10:20 AM
Anoop Kumar Sharma Thank you buddy. I am glad you liked it.
Abhishek JaiswalPosted Apr 14, 2015, 10:00 AM
Nicely Explained.. Helpful! :)
Anoop Kumar SharmaPosted Apr 14, 2015, 10:00 AM
Nice Article. Thanks.. :-)
Ajay BhasyPosted Apr 14, 2015, 7:54 AM
Good one for beginners and nicely explained. Step by step approach.
Sibeesh VenuPosted Apr 14, 2015, 7:47 AM
Nitin Tyagi Thank you buddy.
NitinPosted Apr 14, 2015, 6:56 AM
very well explained...
Sibeesh VenuPosted Apr 14, 2015, 6:33 AM
Shubham kumar Thank you so much dude.
Shubham KumarPosted Apr 14, 2015, 4:37 AM
looking forward for database connectivity in AJ
Shubham KumarPosted Apr 14, 2015, 4:35 AM
good one
Sibeesh VenuPosted Apr 14, 2015, 4:05 AM
Santhakumar Munuswamy Thank you so much.
Santhakumar MunuswamyPosted Apr 14, 2015, 3:55 AM
Thanks for nice article
Sibeesh VenuPosted Apr 14, 2015, 3:32 AM
Prasham Sabadra Thank you so much.
Prasham SabadraPosted Apr 14, 2015, 1:15 AM
Nicely explained. Thanks!
Sibeesh VenuPosted Apr 14, 2015, 1:04 AM
Ashish Kalra Thank you.
Ashish KalraPosted Apr 14, 2015, 1:01 AM
gud 1