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 Cheap Jaguars Shirts , 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 Cheap Jaguars Jerseys , 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 A. J. Cann Hat , 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 Yannick Ngakoue Hat , 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 Dede Westbrook Hat , 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 Cam Robinson Hat , which demonstrates how to bind an input value to an
element.
Name:
Enter a name here
Hello, {{yourName}}!
In AngularJS, a template is just plain-old-HTML. The HTML vocabulary is extended Logan Cooke Hat , 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.
It is important to realize that at no point does AngularJS manipulate the template as strings. The input to AngularJS is browser DOM and not an HTML string. The data-bindings are DOM transformations, not string concatenations or inner HTML changes. Using the DOM as the input Ronnie Harrison Hat , rather than strings, is the biggest differentiation AngularJS has from its sibling frameworks. Using the DOM is what allows you to extend the directive vocabulary and build your own directives, or even abstract them into reusable components!
One of the greatest advantages to this approach is that it creates a tight workflow between designers and developers. Designers can mark up their HTML as they normally would, and then developers take the baton and hook in functionality Telvin Smith Hat , via bindings with very little effort.
Here is an example where I am using the ng-repeat directive to loop over the images array and populate what is essentially an image template.
}
{{ ription}}
It is also worth mentioning, as a side note, that AngularJS does not force you to learn a new syntax or extract your templates from your application.
Feature 3: MVC
AngularJS incorporates the basic principles behind the original MVC software design pattern into how it builds client-side web applications.
The MVC or Model-View-Controller pattern means a lot of different things to different people. AngularJS does not implement MVC