AngularJS入門學習筆記一

來源:互聯網
上載者:User

標籤:name   學習筆記   相關   color   book   src   範圍   針對   ide   

首先聲明:

本部落格源自於學習:跟我學AngularJs:AngularJs入門及第一個執行個體。通過學習,我自己的一些學習筆記。

1.AngularJS的一些基本特性

(1)使用雙大括弧{{}}文法進行資料繫結;

(2)使用DOM控制結構來實現迭代或者隱藏DOM片段;

(3)支援表單和表單的驗證;

(4)能將邏輯代碼關聯到相關的DOM元素上;

(5)能將HTML分組成可重用的組件。

 

他是MVC結構的,有雙向資料繫結的特點。是雙向資料繫結的圖解:

 

使用DOM作為輸入,而不是字串,是AngularJS區別於其它的架構的最大原因。使用DOM允許你擴充指令詞彙並且可以建立你自己的指令,甚至開發可重用的組件。---這句話我還沒有理解。之後理解了,我再解釋。

HTML模板將會被瀏覽器解析到DOM中。DOM然後成為AngularJS編譯器的輸入。AngularJS將會遍曆DOM模板來產生一些指導,即,directive(指令)。所有的指令都負責針對view來設定資料繫結。

MVC:

以上只是一些雜亂的特性。當我深入學習了之後,會更好的分門別類的列舉和寫出具體的特性。

入門執行個體一:

<p><input  type="text" ng-model = "inputValue">請輸入內容</p>  

 <h1>您輸入的內容為:{{inputValue}}</h1>  

angular通過 ng-model將input輸入框輸入的內容,綁定到一個叫inputValue的model上。

然後再用雙大括弧將這個model綁定到h1上面。

入門執行個體二:

代碼如下:

<!DOCTYPE html>  <html lang="en" ng-app="myApp">  <head>      <meta charset="UTF-8">      <title>AngularJS入門</title>      <script type="text/javascript"  src="./1.5.3/angular.min.js"></script>  </head>  <body ng-controller = "myController">      <p><input  type="text" ng-model = "inputValue">請輸入內容</p>      <h1>您輸入的內容為:{{inputValue}}</h1>  </body>  <script type="text/javascript">  var app = angular.module(‘myApp‘, []);//獲得整個angularJS影響的html元素  //控制器  app.controller(‘myController‘, function($scope) {      $scope.inputValue = "PeterTest";  });  </script>  </html>  

 

注意以上代碼標黃的部分。這兩個分別批明了AngularJS有效範圍和Controller層有效範圍。

先通過  var app = angular.module(‘myApp‘, []);  拿到整個angularJS影響的app對象。

再通過app.controller拿到myController,

然後讓input的資料與注入到我們控制器函數的範圍($scope)相關聯。

從而一開啟頁面,就自動填滿好了 PeterTest。

    $scope.inputValue = "PeterTest"; 
angularJS實戰

來自於學習慕課網 http://www.imooc.com/video/2678  angularJS實戰的一些筆記。

最終實現一個bookstore應用

 

AngularJS入門學習筆記一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.