Back to blog home page

The PROs of AngularJS

Posted by on May 05, 2015

Overview

Building off our infographic on the pros and cons of developing in AngularJS, we felt that some of the points we made deserved a bit of a deeper explanation. In this article we’ll look at the pros of Angular development. We’ll cover the major benefits of working in Angular, diving a bit deeper into the aspects of the framework that may not be immediately obvious.

Prototyping and Development Speed

One of the primary benefits of AngularJS is that it encapsulates a lot of the underlying JavaScript architecture of a project. This means that a lot of the glue code you would usually need to write to tie an interface to underlying data management is simply not needed. This, coupled with the framework’s natural expressiveness, allows a developer to introduce new features a lot more quickly than when working with JQuery or plain JavaScript. This is crucial when your app is in the prototyping phase – Angular’s succinct expressiveness allows for very rapid prototyping, letting your developers and designers quickly work together to settle on a representative sample app.

Dependency Injection

Dependency injection is one of the most complex features of AngularJS, and as a result is one of the most challenging to understand. Dependency Injection is the process that AngularJS uses to attempt to determine which class to use for a parameter based upon the name of the parameter itself. The core of the pattern lies in completely decoupling an object’s implementation from its usage. Where a code base without dependency injection might look like the following:

Code written using dependency injection would resemble the following:

Ultimately, this allows the code making use of the HTTP service to focus on using the service itself, instead of having to worry about how to construct it each time. It dynamically injects module dependencies into the function call by doing back-end parsing of parameter names that it then matches to defined classes. The practical upshot is that you can both compartmentalize your app more cleanly, and that you can more easily test the intended functionality of a method without having to build a complex mock or double framework by simply providing your own overridden dependencies.

Easy Testability

One of the primary goals of AngularJS development was to ease test-driven development. As a result, testing in AngularJS is a first-class citizen throughout the framework. Building off of features like Dependency Injection detailed above, mocking out aspects of the framework is quick to implement and relatively simple to use. This allows your team to build a suite of tests that verify your application’s functionality from day one. In addition, several testing frameworks (such as Karma) make end-to-end functional testing relatively simple to integrate into your test suite.

Conclusion

AngularJS has a lot going for it when it comes to enhancing the development experience. From a code structure that extends the basic HTML language using familiar declarative data patterns to techniques such as two-way data binding and dependency injection, AngularJS provides a developer with a lot of tools to accomplish the same tasks as other frameworks with higher development velocity and fewer overall lines of code. However, AngularJS is not without its downsides. In the next post, we’ll look at some of the downsides to AngularJS development that should be taken into consideration when selecting an implementation environment.