Well, the short answer is you don’t have to make a choice, since they work perfectly well together.
But let’s take a look at some of the differences and similarities so that you can make an informed decision of what to use and when.
From ~ 2006, several first generation javascript frameworks were developed, namely jQuery, Prototype, mootools, and YUI. These focussed on DOM manipulation (ie when X event happens, do Y on element Z) and grew rapidly in adoption until jQuery generally became acknowledged as the most widely adopted “standard”.
With increasing demand for interaction on web pages, the next generation of JS frameworks were released around ~2010. The most popular include:
These were particularly suited for MVC client-side applications, and the main difference was they focussed on what should change, ie X is an attribute of Y (and so automatically change X when Y changes).
This was a significant difference to the jQuery approach, and allowed developers to think conceptually of the web app as a collection of data objects, instead of as a collection of DOM elements to be manipulated. That is, a transition from imperative to declarative programming.
1st gen frameworks (ie jQuery) think “when X event happens, do Y”
2nd gen frameworks (ie AngularJS) think “X is an attribute of Y” (so automatically change X when Y changes)
The rest of this article now focusses on the differences between the “standard” in the first generation (jQuery), and what I believe will become the standard in the second generation - AngularJS.
In my opinion, there are 3 strong reasons why I prefer Angular over jQuery.
For applications which model complex database relationships (i.e. any application with several data objects), any change in a model object or attribute will automatically update all other sections of the DOM which are affected.
For example, an ecommerce shopping cart which requires summing up the prices of several products. In this scenario, adding a new product can automatically update the total section without requiring any explicit changes to the page elements.
AngularJS decouples the HTML (e.g. class names, ids, etc) from the javascript functions, by using models to establish relationships between objects this makes refactoring and changing UI simpler
As a follow on effect of item 2 above, these frameworks also enable JS unit testing (using tools like Jasmine) which is much trickier for jQuery.
Illustrated by a simple example - say we want a basic calculator which multiplies a qty
input with a cost
input to display a total
value.
In jQuery, this would be something like:
$("#qty, #cost").on('change', function(){
var qty = $("#qty").val();
var cost = $("#cost").val();
$("#total").html( parseInt(qty) * parseInt(cost) );
})
In AngularJS, this would be something like:
<div ng-app ng-init="qty=1;cost=2">
<b>Invoice:</b>
<div>
Quantity: <input type="number" ng-model="qty" required >
</div>
<div>
Costs: <input type="number" ng-model="cost" required >
</div>
<div>
<b>Total:</b> {{qty * cost | currency}}
</div>
</div>
Read on for a short summary of the differences
Angular seems to be the most widely searched
Angular seems to have the most active community (starred 22K times on Github, vs 18K for Backbone, 12K for Metero, 10K for EmberJS, and 5K for React)
Angular is supported by Google, but does not appear to be used by a lot of production-grade apps. Most examples are prototype standard only.
BackboneJS also does not appear to be used by a lot of production-grade apps
EmberJS claims to be used by larger startups like Square, Groupon, LivingSocial
ReactJS is used by Facebook in production
React is too simplistic (just the “V” in “MVC” and still needs to be paired with Backbone or Angular)
Meteor is currently too immature (version 0.8.0) to be used in production
EmberJS and Backbone are more mature and possible contenders, but Angular’s popularity suggests it will quickly become the de-facto standard
Angular has a good balance of maturity, community support, and productivity - making it a suitable choice for production apps.