Mastering Web Application

(Rick Simeone) #1

Angular Zen


Why use AngularJS modules


The fact that AngularJS combines all the services from all the modules into one
application-level namespace might come as a surprise, and you might wonder
why to use modules. At the end of the day, all the services are ending up in one big
bag, so what is the point of laboriously dividing services into individual modules?


AngularJS modules can help us organize multiple JavaScript files in an application.
There are many strategies for dividing an application into modules, and we are
going to spend a big portion of Chapter 2, Building and Testing discussing different
approaches, their pros, and cons. Also, small and focused modules help facilitate
unit testing as we can load a well-identified set of services under test. Once again,
Chapter 2, Building and Testing, has more details.


AngularJS and the rest of the world


Choosing a perfect framework for your next project is not easy. Some frameworks
might be a better fit for certain types of applications and team's experience, personal
preferences, as well as many other factors can dictate the ultimate choice.


AngularJS will be inevitably be compared to other popular JavaScript MV*
frameworks. Different comparisons will most probably yield different results,
and different points of view will fuel many passionate discussions. Instead of
offering hard-and-fast rules or feature-by-future comparisons, we would like
to summarize how AngularJS is different compared to other frameworks.


If you would like to see how code written with AngularJS compares
to code written with other frameworks, the TodoMVC (http://
addyosmani.github.com/todomvc) is the place to go. This is a
project where one can see the same sample application (TODO list)
reimplemented using different JavaScript MV* frameworks. This is
a unique opportunity to compare architectural approaches and code
syntax, its size, and readability.

There are many things about AngularJS that make it stand out from the crowd.
We saw already that its approach to UI templates is quite novel, as mentioned in
the following features:



  • Automatic refresh and the two-way data binding frees developers from
    the tedious work of explicitly triggering UI repaints

  • Live DOM generated from HTML syntax is used as a templating language.
    More importantly, it is possible to extend an existing HTML vocabulary (by
    creating new directives), and then build UIs using a new HTML-based DSL

Free download pdf