AngularJS
AngularJS - Simply known as Angular - is an open- source framework from Google, which supports the creation of browser- based single -page applications with a MVC model to simplify the software development and testing components corresponding applications.
Structure
Controller
In Angular a ViewModel is defined together with the logic in a controller. Controllers are then combined into a single module. The modules are integrated using an integrated dependency injection container. The view is connected to the ViewModel. Thereby a bi-directional data link between the view and the logic is made possible.
Directives
Angular allows your own HTML elements and attributes in the form of directives to define.
Predefined directives are recognized by the ng namespace in the prefix. The type of the prefix to be used is dependent on the Validator.
To select items from AngularJS jQuery Light ( jqLite ) is used, a reduced version of jQuery. If jQuery included in the HTML DOM, this will take jQuery Light used.
Double curly syntax interpolation
Angular also offers a double- curly syntax interpolation. This JavaScript expression in double curly braces. Here, however, no jump instructions are supported. Similar filter supports Unix filters | Instead, with the pipe operator.
Alternatively, ng -bind can be used. The < / span > command has the same result as { {name } } < / span >, but with the difference that the browser does not display anything before the corresponding data has been loaded.
Services
Services include business logic, and connect external resources - about REST web services - a. Services thus correspond to the model in the MVC model. Services are instantiated as a singleton.
To perform AJAX requests are in the $ AngularJS http object and the $ resource - object. Both internal access to the XMLHttpRequest object, and differ in the degree of abstraction. While $ http arbitrary HTTP requests can perform, $ resource specializes in REST services.
In addition, there are specialized services from third parties.
Communication
This controller can communicate with other controllers or services will be provided by $ scope or $ from $ rootScope object emitted and $ broadcast methods. This serves to emit $ to send messages to all parent scopes, while $ broadcast serves to send messages to child scopes.
In order for a controller or service can respond to a message, it must or it register for the message using the $ on method for the message type ( publish-subscribe method ).
Routes in single-page applications
In order to define routes in single-page application (SPA) is provided by the AngularJS ngRoute module. About this routes can be defined. The ngRoute module can dynamically reload views in an element with the ng -view directive.
However, a single -view ng directive per page, it is only possible to specify. Remedied UI router AngularUI project.
In addition, the $ location object allows direct processing of the browser URL to simulate a page navigation.
Hello world program
Below is a small hello world program is shown in AngularJS.
In Default.html:
xml version = " 1.0" encoding = "UTF -8"? >