Developer Guide: Overview

What Is Angular?

The short answer: angular is a new, powerful, client-side technology that makes it much easier for you to create dynamic web sites and complex web apps, all without leaving the comfort of your HTML / JavaScript home.

The long answer: it depends on where you're coming from...

Angular is not just a templating system, but you can create fantastic templates with it. Angular is not just a web framework, but it features a very nice framework. Angular is not just an extensible HTML compiler, but the compiler is at the core of Angular. Angular includes all of these components, along with others. Angular is far greater than the sum of its parts. It is a new, better way to develop web applications!

An Introductory Angular Example

Let's say that you are a web designer, and you've spent many thous — erm, hundreds of hours designing web sites. But at this point, the thought of manipulating the DOM, writing listeners and input validators, all just to implement a simple form? No. You either don't want to go there in the first place or you've been there and the thrill is gone.

So look over the following simple example written using angular. Note that it features only the templating aspect of angular, but this should suffice for now to quickly demonstrate how much easier a web developer's life can if they're using angular:

 <b>Invoice:</b>
 <br/>
 <br/>
 <table>
  <tr><td> </td><td> </td>
  <tr><td>Quantity</td><td>Cost</td></tr>
  <tr>
    <td><input name="qty" value="1"
ng:validate="integer:0"
ng:required/></td>
    <td><input name="cost" value="19.95"
ng:validate="number"
ng:required/></td>
  </tr>
 </table>
 <hr>
 <b>Total:</b> {{qty * cost | currency}}

Try out the Live Preview above, and then let's walk through the example and describe what's going on.

In the <html> tag, we add an attribute to let the browser know about the angular namespace:

    <html xmlns:ng="http://angularjs.org">

This ensures angular runs nicely in all major browsers.

In the <script> tag we do two angular setup tasks:

  1. We load angular.js.
  2. The angular ng:autobind directive tells angular to compile and manage the whole HTML document.

    <script src="http://code.angularjs.org/0.9.15/angular-0.9.15.min.js" ng:autobind></script>

From the name attribute of the <input> tags, angular automatically sets up two-way data binding, and we also demonstrate some easy input validation:

    Quantity: <input name="qty" value="1" ng:validate="integer:0" ng:required/>
    Cost: <input name="cost" value="199.95" ng:validate="number" ng:required/>

These input widgets look normal enough, but consider these points:

And finally, the mysterious {{ double curly braces }}:

     Total: {{qty * cost | currency}}

This notation, {{ _expression_ }}, is a bit of built-in angular markup, a shortcut for displaying data to the user. The expression within curly braces gets transformed by the angular compiler into an angular directive (ng:bind). The expression itself can be a combination of both an expression and a filter: {{ expression | filter }}. Angular provides filters for formatting display data.

In the example above, the expression in double-curly braces directs angular to, "Bind the data we got from the input widgets to the display, multiply them together, and format the resulting number into output that looks like money."

The Angular Philosophy

Angular is built around the belief that declarative code is better than imperative when it comes to building UIs and wiring software components together, while imperative code is excellent for expressing business logic.

Not to put too fine a point on it, but if you wanted to add a new label to your application, you could do so by simply adding text to the HTML template, saving the code, and refreshing your browser:

<span class="label">Hello</span>

Or, as in programmatic systems (like GWT), you would have to write the code and then run the code like this:

var label = new Label();
label.setText('Hello');
label.setClass('label');
parent.addChild(label);

That's one line of markup versus four times as much code.

More Angular Philosophy

Now that we're homing in on what angular is, perhaps now would be a good time to list a few things that angular is not:

Why You Want Angular

Angular frees you from the following pain:

Watch a Presentation About Angular

Here is an early presentation on angular, but note that substantial development has occurred since the talk was given in July of 2010.

Presentation | Source