1.ANGULARJS Features
MVC Mode module System instruction system Dependency injection bidirectional data binding
2. $scope and $rootscope
$scope is a local scope, $rootscope is the global scope. when used with NG-controller, the global scope ($rootscope) is found first from the current scope ($scope) when looking for a variable.
The formal parameter of the function is $scope, $rootScope cannot be modified, Testscope is automatically called inside the angular, and these two parameters are automatically dependent injected when internally called. These two parameters are called services, and the General Service begins with $.
function testscope ($scope, $rootScope) { = ' Test '; = 1; } <div ng-controller= "Testscope" > <p>{{name}}</p> </div> <p>{{age}} </p>
3. Data binding
{{}} is used for data binding, or you can use ng-bind. or <p ng-bind= "TXT" ></p> the other is {{}}html} is not loaded, {{txt}} back directly to the page, Until angular renders the bound data (this behavior is likely to be visible to the user by {{binding}}), while Ng-bind displays the data after the angular rendering is complete
4.ng-controller and Ng-app
ng-Controller The bridge between link view and model data, can introduce multiple controllers as needed Ng-app similar to initialize call angular instruction, can write to any HTML tag, Angular function within the scope of the corresponding label. The HTML tag adds a NG-app attribute, meaning that the entire HTML belongs to the Angularjs control ;
5. Bidirectional data binding
like the MVVM design pattern, when m (model data) changes, it automatically changes the V (View view HTML), and when V changes, the M is automatically changed. M-V: $timeout directive: similar to SetTimeoutfunctiontesttimeout ($scope, $timeout) {$scope. Name= ' First '; $timeout (function() {$scope. Name= ' Second '; },2000)} ng-Click Command: similar to onclickfunctionTestclick ($scope) {$scope. Name= ' First '; $scope. Change=function() {$scope. Name= ' third '; } } <div ng-controller= "Testclick" ng-click= "name= ' third '" > <p>{{name}}</p> </div>or<div ng-controller= "Testclick" ng-click= "Change ()" > <p>{{name}}</p> </div>V-M:ng-Model: Talk value is bound to form element<input type= "text" ng-model= "YourName" placeholder= "Enter a name here"/> <P>{{YOURNAME}}</P&G T5.currrency: Filter
An expression |currency formatted as dollar: $ expression Value Expression|currency: "¥"formatted as RMB: ¥ value of expressionfunctiontestcurrency ($scope) {$scope. IPhone={price:50, Num:3 }; $scope. Count=function(){ return$scope. Iphone.price *$scope. Iphone.num; } } <div ng-controller= "Testcurrency" > <p> Price: <input type= "text" ng-model= "Iphone.price"/></P&G T <p> Quantity: <input type= "text" ng-model= "Iphone.num"/></p> <p>{{iphone.price * iphone.num}}& Lt;/p> <p>{{count ()}}</p> <p>{{iphone.price * Iphone.num |currency}}</p> ; <p>{{Iphone.price * iphone.num |currency: ' ¥ '}}</p> </div>6. Current Learning Demo
<!DOCTYPE HTML><HTMLNg-app><Head><MetaCharSet= "Utf-8"><Metahttp-equiv= "X-ua-compatible"content= "Ie=edge,chrome=1"><title>Examples</title><Scripttype= "Text/javascript"src= "Http://ngnice.com/lib/angular/1.2.16/angular.js"></Script><Scripttype= "Text/javascript"> functionTestscope ($scope, $rootScope) {$scope. Name= 'Test'; $rootScope. Age= 1; } functiontesttimeout ($scope, $timeout) {$scope. Name= ' First'; $timeout (function() {$scope. Name= 'Second'; }, -) } functionTestclick ($scope) {$scope. Name= ' First'; $scope. Change= function() {$scope. Name= 'Third'; } } functiontestcurrency ($scope) {$scope. IPhone={price:5, Num:3, Free:Ten }; $scope. newval= ""; $scope. Oldval= ""; $scope. Count= function(){ return$scope. Iphone.price*$scope. Iphone.num+$scope. Iphone.free; }; }</Script></Head><Body> <Div> <label>Name:</label> <inputtype= "text"Ng-model= "YourName"placeholder= "Enter a name Here"> <BR> <H1Ng-bind= "YourName"></H1> <H1>Hello {{yourname}}!</H1> </Div> <BR/> <DivNg-controller= "Testscope"> <P>{{Name}}</P> </Div> <P>{{Age}}</P> <DivNg-controller= "Testtimeout"> <P>{{Name}}</P> </Div> <DivNg-controller= "Testclick"Ng-click= "Change ()"> <P>{{Name}}</P> </Div> <inputtype= "text"Ng-model= "TestName"placeholder= "Enter a name Here"> <P>{{testname}}</P> <DivNg-controller= "Testcurrency"> <P>Price:<inputtype= "text"Ng-model= "Iphone.price"/></P> <P>Number:<inputtype= "text"Ng-model= "Iphone.num"/></P> <P>Shipping:<inputtype= "text"Ng-model= "Iphone.free"/></P> <P>{{Iphone.price * iphone.num + Iphone.free}}</P> <P>{{count ()}}</P> <P>{{Iphone.price * iphone.num + iphone.free |currency}}</P> <P>{{Iphone.price * iphone.num + iphone.free |currency: ' ¥ '}}</P> </Div></Body></HTML>ANGULARJS Study notes (1)