AngularJS is a Javascript MVC framework created by Google to build properly architectured and maintenable web applications.
AngularJS takes another approach. It attempts to minimize the impedance mismatch between document centric HTML and what an application needs by creating new HTML constructs. AngularJS teaches the browser new syntax through a construct we call directives. Examples include:
Data binding T. J. Logan Womens Jersey , as in {{}}. DOM control structures for repeating, showing and hiding DOM fragments. Support for forms and form validation. Attaching new behavior to DOM elements, such as DOM event handling. Grouping of HTML into reusable components.
Why AngularJS?
AngularJS is an MVC framework that defines numerous concepts to properly organize our web application. Our application is defined with modules that can depend from one to the others. It enhances HTML by attaching directives to your pages with new attributes or tags and expressions in order to define very powerful templates directly in your HTML. It also encapsulates the behavior of your application in controllers which are instanciated thanks to dependency injection. Thanks to the use of dependency injection, AngularJS helps you structure and test your Javascript code very easily. Finally Chad Williams Womens Jersey , utility code can easily be factorized into services that can be injected in your controllers. Now let鈥檚 have a closer look at all those features.
Feature 1: Two Way Data-Binding
Think of your model as the single-source-of-truth for your application. Your model is where you go to read or update anything in your application.
Data-binding is probably the coolest and most useful feature in AngularJS. It will save you from writing a considerable amount of boilerplate code. A typical web application may contain up to 80% of its code base, dedicated to traversing, manipulating, and listening to the DOM. Data-binding makes this code disappear Budda Baker Womens Jersey , so we can focus on our application.
Think of your model as the single-source-of-truth for your application. Your model is where you go to read or update anything in your application. The data-binding directives provide a projection of your model to the application view. This projection is seamless, and occurs without any effort from you.
Traditionally, when the model changes, the developer is responsible for manually manipulating the DOM elements and attributes to reflect these changes. This is a two-way street. In one direction Haason Reddick Womens Jersey , the model changes drive change in DOM elements. In the other, DOM element changes necessitate changes in the model. This is further complicated by user interaction, since the developer is then responsible for interpreting the interactions, merging them into a model Christian Kirk Womens Jersey , and updating the view. This is a very manual and cumbersome process, which becomes difficult to control, as an application grows in size and complexity.
There must be a better way! AngularJS鈥?two-way data-binding handles the synchronization between the DOM and the model, and vice versa.
Here is a simple example Josh Rosen Womens Jersey , which demonstrates how to bind an input value to an
element.
Name:
Enter a name here
Hello, {{yourName}}!
This is extremely simple to set up, and almost magical鈥?p>
Feature 2: Templates
It鈥檚 important to realize that at no point does AngularJS manipulate the template as strings. It鈥檚 all the browser DOM.
In AngularJS, a template is just plain-old-HTML. The HTML vocabulary is extended Sam Bradford Womens Jersey , to contain instructions on how the model should be projected into the view.
The HTML templates are parsed by the browser into the DOM. The DOM then becomes the input to the AngularJS compiler. AngularJS traverses the DOM template for rendering instructions, which are called directives. Collectively, the directives are responsible for setting up the data-binding for your application view.