Beginning AngularJS

(WallPaper) #1
Chapter 2

The Basics of AngularJS


JavaScript is an important language for web developers—one that is nearly impossible to ignore. It’s a language
that was created for the relatively simple purpose of adding basic interactivity to web pages. However, it has risen to
mainstream importance, and it is used today to build large and sophisticated web applications.


Why We Need Frameworks


You may develop some appreciation of why frameworks such as AngularJS exist, by considering that JavaScript was
not originally created with today’s much more complex requirements in mind. In fact, in many respects, JavaScript
was adapted to this purpose because it was there. It was already widely supported in web browsers, and many
developers knew how to use it.
JavaScript sometimes gets a bad rap; it isn’t everyone’s favorite language. I personally enjoy using it and find that
I can work around the things that I perceive as shortcomings; nevertheless, I totally understand why some developers
don’t feel the same way as I do, particularly those who have not had the chance to warm up to its strengths. I think it is
fair to say that JavaScript has many great features, but it is equally fair to say that it is missing a few features—ones that
developers feel are vital.
Given its humble beginnings and perceived shortcomings, is JavaScript really ideal for developing modern web
applications? It certainly is. As a relatively easy-to-learn language with almost ubiquitous support, it is extremely well
suited to the task.
Here’s a better question: Is JavaScript ideal for developing applications that require modularity, testability, and
developer productivity? The short and simple answer to a question such as this is no, not really. At least not “out of the
box.” The makers of JavaScript simply didn’t have these requirements in mind when it was conceived. However, today
we have a proliferation of frameworks and libraries designed to help us with such things. The general idea is that we
want to be more productive and that we want to write code, often in response to unreasonably tight deadlines, that we
can easily maintain and reuse. This is why we need frameworks.
Each framework achieves its (sometimes significantly different) objectives in a variety of ways and to varying
degrees. For example, the popular jQuery framework addresses direct Document Object Model (DOM) manipulation
extremely well, but it doesn’t really help out much when it comes to keeping your code structured and organized.
To be fair, jQuery is more of a library than a full-fledged framework, so this really relates more to my point about
varying objectives and degrees.
With regard to front-end web development, AngularJS addresses many, if not all, of the issues developers face
when using JavaScript on its own, and it does so in a very elegant and comprehensive way.
There often isn’t a right or wrong framework, by the way, because much of what constitutes right may depend
on the kind of project on which you are working, your current skills and experience, and your personal preferences.
That being said, I personally believe that AngularJS is a great all-around framework, which is definitely among the
best available.

Free download pdf