Features of Angular JS
One of my tech lead Arun Gopi said in between
2011 that the “JavaScript gonna own the developer world in coming future”.
I didn’t care about his quote, i thought what is possible with this
lightweight scripting language, it can do some kind of client side
programmings other than that it is useless. On that period i was not aware
about the possibilities of javascript. There were lots of inventions of
javascript frameworks on the time of 2011. And now with this lightweight
scripting language we can do server side programmings, game developments,
desktop applications and mobile
applications etc. The JS frameworks build by some big bang companies made the
JS so much popular. Some of the best popular JS frameworks are BackBone.js,
Ember.js, Angular.js, Extjs (Sencha) etc. In these framework the most popular
and hottest framework is AngularJS. How it come most popular and hottest one
among these frameworks? It should have that much features and backed up
supports. Since it is developed by google, there is no need of doubt on support
for AngularJS. About the features, there is lots of comments are coming from
different forums and blogs about the features of angular js. I started working on angular js and found
the features of angular js is pretty cool. I am interested to share some of the
features what i felt while developing in Angularjs.
Data Binding.
Most of the time , the data should be retrieve from the server and
should show it visually. For this we always need to get data from server and
assigned to a model and then this model is set to the corresponding view. If
any change happened to the views it should reflect the model which we assigned
so the events should be listened for the change in view. Also there will
be reverse case if there is any change happened to the model it should reflect
the view also. So implementing this we need to write codings to implement the
logic. The one of the interesting and which would i look most curiously look
into the feature of angular js will do the things which i have explained
earlier. Since the feature of Two Way Data Binding, if we assign a model for a view
then whenever a change is happened to the model it will automatically reflect
to the view and whenever there is event have occurred in the views it will
automatically reflect to the models. If any manual changes is required then
this can be done by some of the functions provided by the AngularJS like $watch, $digest, $apply etc.
MVC
Every developers would like to develop their software in a
structured manner. Because it will be very helpful for coding, editing on them
and easy to handle. For structuring the projects the best way is MVC
Model-View-Controller concept. Most of the JavaScript framework will tell to do
in MVC pattern and developers needed to implement it. In the case of AngularJS,
it is implemented in such a way. Here the view is the projection of the model,
whenever there is any change in model it will shown in view and vice versa. The
changes for the models can be done by writing functions in controllers. Here
view will be written in html files and there will be a controllers for these
html files. These controllers will be assigned to html file with the help of
directive called ng-controller. And there will be a scope
variable for the controller.This scope variable will have the some properties
and these will be the models. Your controller will be responsible for binding
model data to views using $scope.
Services
We have gone through the two way data binding and MVC structure. Now we need to know how to write the business logic in AngularJS. As we discussed above the controller will bind the data does and it not contain the code to fetch the data and manipulating it. We can use Services for implementing the business logic and manipulations. Services is a singleton object which contain some useful functions. These functions can be used from anywhere from controller, filters etc. What should do to access these function is to inject the services into the controllers (which means just include the service). We can declare service in different ways, in that mostly used couple of methods are module.factory and module.service. We can use services to pass datas from one controller to another controller with the help of $broadcast and $on. $broadcast is used to dispatch an event to the child scope which is registered to these event. $on will listen these event and will do the coding when these functions are triggered.
Directives
One of the important component angularjs is directive. Most of the things we used in angularjs will be directives. Some of them are ng-repeat, ng-if, ng-switch, ng-model etc. Directive is the root of angular js and it makes the angular js more powerful. One of the interesting directive is ng-repeat. Most of them might know about the ng-repeat who have created a single angular app. With the help of this directive we can easily populate a data into a list or table etc. The basic idea behind directive is very simple. It makes your HTML truly interactive by attaching event listeners to the elements and/or transforming the DOM. It is possible to implement your own directives too. This is what AngularJS refers to as "teaching HTML new tricks".
Write less achieve more
The most likely thing is we can achieve our goal by writing less code. From the above features i have explained above it is understandable that there is no need of large amount of coding needed for data manipulations and reflecting changes with respective to models. We can easily write reusable things with the help of directives. We can implement the business logic, server communications and transfer data between controllers with services.The MVC pattern coding make our more app structured and it will help for write less.
The above features can be also seen in many forums and blogs which is explained very well. While reading those things i felt every one are saying the same kind of features and they might be writing after reading a base forums. But when i tried working on angularjs and experienced the extraordinary cool features and understood why they praise about these features. If you didn’t start coding on angular js, please taste it and you gonna love it.
Sincere thanks to Shibu Basheer our great CTO who allowed me to research on Angular JS
ENJOY CODING :)