Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

From the basic Angular tutorial, it seems like all it does is fetch some JSON from an API and display it. Also, there's its double binding magic.

But why would I use it instead of a backend solution (like Rails) that builds the view in the backend and serves it to the user, with everything in place already? What are the use cases?

share|improve this question

2 Answers

TLDR;

Angular helps you deal with the complexity inherent in rich user interfaces. As UI complexity increases, the traditional model of generating pages on the server gets much more complex. Angular lets you decompose your UI into manageable chunks, and allows you to separate the UI from the implementation. This makes server-side page generation a great deal easier, but Angular really comes into its own when you make the move to pure javascript-based applications. A good example of such an application is Trello.

The long story

Angular isn't really target at sites that you can comfortably implement by generating everything on the server, and sending it across. Furthermore, whilst that is a perfectly good approach that works for many sites and applications around the internet, it becomes increasingly complex (thus difficult) to keep that approach working as you try to increase the level of interactivity in your site.

Ultimately the way you solve this is by pushing your UI more and more into the Javascipt side of the equation. Angular lets you break your UI up into components, giving you clear separation between the look-and-feel, and the how-it-works. You can then build fairly simple pages on the server, and the JS front end the creates the rich UI, which makes separate calls back to your server for the data they need.

There comes a point, though, where all you want to do is server a stub page that loads a completely javascript-based application. Probably the most well known example of the sort of use-case where Angular really shines is Trello (it uses Backbone, not Angular, but it is the same use-case). There is a site http://builtwith.angularjs.org/ which has more example sites that use Angular.

So the short answer? Angular makes it easier to create rich, highly interactive user interfaces by letting you decompose your UI into components, and ultimately go completely javascript.

share|improve this answer
AngularJ sodesn't provide clear separation of look and feel and logic. – rsman May 10 at 2:11
3  
@rsman, it clearly does. The whole point of the data-binding is that you don't write a whole bunch of DOM-manipulation code, angular does it for you, ergo, you define what it looks like, you define how your interactions etc work, but you avoid having to couple those two together with code that updates what it looks like from code that handles interactions. – guysherman May 10 at 2:44

It is about making more responsive user interfaces. The double binding, dependency injection and so on makes it possible to create dynamic pages quite easily. You can write directives in Angular which gives you a declarative way to construct a view.

As an example, in a current project we have a view that uses several hundred lines of JavaScript code in order to make a responsive user experience. Even so the page is a bit buggy and very difficult to maintain. We started looking around for a better option and looked at backbone.js and knockout.js. Eventually we tried Angular. We were able to create a much more responsive and maintainable page with just a few lines of code. Gone was all the DOM manipulation code. Gone was all the clunky backend view creations that had to be fetched and inserted at the right places. Gone was all the code that was written to keep the model and the view in sync. With that experience the decision to move to Angular became easier and so far we have not regretted it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.