6 Reasons Why You Should Use AngularJS
Before diving into reasons why you should use AngularJS in your apps, I would like to share some informations about AngularJS with you guys.
AngularJS is an open source web application framework. It was originally developed in 2009 by Misko Hevery and Adam Abrons. It is now maintained by Google.
Definition of AngularJS as put by its official documentation is as follows −
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. Angular’s data binding and dependency injection eliminate much of the code you currently have to write. And it all happens within the browser, making it an ideal partner with any server technology.
So the important thing here is, with AngularJS, you can do lots of stuff without tiring server.
Anyway, here are the reasons why you should use AngularJS.
I can nearly hear you saying that, what the heck, should I use Angular because of the feature that almost every other languages has too?
No, not like that.
Angular is doing MVC right.
Most frameworks implement MVC by asking you to split your app into MVC components, then require you to write code to string them up together again. That’s a lot of work. Angular implements MVC by asking you to split your app into MVC components, then just let Angular do the rest. Angular manages your components for you and also serves as the pipeline that connects them.
Because Angular acts as the mediator, developers also won’t feel tempted to write shortcuts between components that break abstractions just to make them fit easier.
MVVM to the Rescue!
Models talk to ViewModel objects (through something called the $scope object), which listen for changes to the Models. These can then be delivered and rendered by the Views, which is the HTML that expresses your code. Views can be routed using the $routeProvider object, so you can deep-link and organize your Views and Controllers, turning them into navigable URLs. AngularJS also provides stateless controllers, which initialize and control the $scope object.
Data Binding and Dependency Injection
What is this?
This is the place where Directives came to the game.
Imagine a world where HTML has so many rich elements that we never have to manipulate the DOM to simulate them. All that our app needs to do is to assign attributes to elements to get any functionality out of the box.
Directives achieve this by enabling us to invent our own HTML elements. By putting all our DOM manipulation code into directives, we can separate them out of our MVC app. This allows our MVC app to only concern itself with updating the view with new data. How the view subsequently behaves is up to the directives.
Unit Testing Ready
This part is my favorite. As you (may) know, unit testing is very important for a developer to examine in his/her code to be sure that code is working clearly – as expected. Now, you may say that,
I don’t need to write Unit test, because my code is as simple as Hello World app
But the thing is, if you want to work for Google, Facebook, Amazon etc. firms, or as even better argument, if you want to be a better developer, you need to write Unit Tests for your code. I would suggest for you guys to take a look at this Unmit Test thing deeply by Googling it.
Anyway, we were saying..
What description of Angular would be complete without talking about it’s unit testing readiness? The whole of Angular is linked together by Dependency Injection (DI). It’s what it uses to manage your controllers and scopes. Because all your controllers depend on DI to pass it information, Angular’s unit tests are able to usurp DI to perform unit testing by injecting mock data into your controller and measuring the output and behavior. In fact, Angular already has a mock HTTP provider to inject fake server responses into controllers.
This beats the more traditional way of testing web apps by creating individual test pages that invoke one component and then interacting with it to see if it works.
I’ve used Karma – Jasmine once, and I liked it veeeery much. It is very easy to write Unit Test with it.
Lastly, I would like to present you..
Pros and Cons of AngularJS
Advantages of AngularJS
- AngularJS provides capability to create Single Page Application in a very clean and maintainable way.
- AngularJS provides data binding capability to HTML thus giving user a rich and responsive experience
- AngularJS code is unit testable.
- AngularJS uses dependency injection and make use of separation of concerns.
- AngularJS provides reusable components.
- With AngularJS, developer write less code and get more functionality.
On top of everything, AngularJS applications can run on all major browsers and smart phones including Android and iOS based phones/tablets.
Disadvantages of AngularJS
Though AngularJS comes with lots of plus points but same time we should consider the following points −