AngularJSApplication
<HTMLNg-app= "Mynoteapp"><Head><MetaCharSet= "Utf-8"><Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></Script></Head><Body><DivNg-controller= "Mynotectrl"><H2>My notes</H2><P><textareaNg-model= "message"cols= "Max"rows= "Ten"></textarea></P><P><ButtonNg-click= "Save ()">Save</Button><ButtonNg-click= "Clear ()">Clear</Button></P><P>Number of characters left:<spanNg-bind= "Left ()"></span></P></Div><Scriptsrc= "Mynoteapp.js"></Script><Scriptsrc= "Mynotectrl.js"></Script></Body></HTML>
Application file "Mynoteapp.js":
var app = Angular.module ("Mynoteapp", []);
Controller file "Mynotectrl.js":
function ($scope) { = ""; $scope.leftfunction() {return - $scope. message.length;}; function () {$scope. Message = "";}; $scope. Save function() {alert ("Note Saved");};});
The
<html ng-app="Mynoteapp">
<div> is the scope of the controller: ng-controller= "Mynotectrl" in the HTML page:
<div ng-controller="Mynotectrl">
The ng-model directive binds <textarea> to the controller variable message:
<textarea ng-model="message" cols="All" rows="ten"></ TextArea>
Two Ng-click events called the Controller function clear () and Save ():
<button ng-click="Save ()">save</button>
<button ng-click="clear ()">clear</button>
The ng-bind directive binds the controller function left () to <span> to display the remaining characters:
Number of characters left:<span ng-bind="left ()"></span>
The application library file needs to be loaded after AngularJs to execute:
<script src="Mynoteapp.js"></script>
<script src="Mynotectrl.js"></script> AngularJS Application Architecture
The above example is a complete AngularJS single page Web application (APPLICATION,SPA).
The ng-app=).
The <div> element defines the scope of the AngularJS controller (ng-controller=).
In an application can be by many controllers.
Application files (my ... App.js) defines the application model code.
One or more controller files (my ... Ctrl.js) defines the controller code.
Summary-How does it work?
The NG-APP directive is located under the root element of the app.
For a single page Web app, the root of the app is usually the
One or more Ng-controller directives define the controller for the application. Each controller has his own scope:: A defined HTML element.
AngularJS automatically starts in the HTML domcontentloaded event. If the ng-app instruction is found, AngularJS loads the module in the instruction and compiles the Ng-app as the root of the application.
The root of the application can be an entire page, or a small portion of the page, and if a small part is compiled and executed faster.
Angularjs Study Chapter (24)