angurlarjs學習筆記

來源:互聯網
上載者:User

標籤:軟體設計   nbsp   otherwise   pad   gen   key   思考   cto   form   

一些需要記憶的知識點:

1、自訂指令:

app.directive("nameDirective" , function(){

  template: ""

});

2、app = angular.module("MyApp", [])

模組定義中,[]表示模組的依賴關係,  應該填寫相依模組的名字, 為null表示沒有依賴關係。

3、注意, 一般將angularjs庫放到head元素中載入, 而AnJS指令碼放到body元素底部載入,原因: 這樣會提高網頁載入速度,因為html載入不受制於指令碼載入。

4、angular.copy() : 複製一個資料到另一個資料 。。 

5、在控制器裡定義方法, 在控制器裡調用方法, 此方法也可以在html中調用。

AnJS  用來代替AJAX 表單提交, 而不是asp.net form表單提交。

6、Form 表單提交 anjs 使用思考:

1234567891011121314151617181920212223242526 <div ng-app="myApp" ng-controller="formCtrl">  <form>    First Name:<br>    <input type="text" ng-model="user.firstName"><br>    Last Name:<br>    <input type="text" ng-model="user.lastName">    <br><br>    <button ng-click="reset()">RESET</button>  <button ng-click="submit()">submit</button>  </form>  <p>form = {{user }}</p>  <p>master = {{master}}</p></div> <script>var app = angular.module(‘myApp‘, []);app.controller(‘formCtrl‘, function($scope) {    $scope.master = {firstName:"John", lastName:"Doe"};    $scope.reset = function() {        $scope.user = angular.copy($scope.master);    };    $scope.reset();    $scope.submit = function(){        /// 把 $scope.user 提交到後台, $http, $.ajax ,  並擷取返回資料<br>          /// http  請求 就是 AJAX 請求    };});</script>

7、 anJS表單 用戶端 驗證:    

input 元素的: required 

$dirty : 表單有填寫記錄,為true , 更改表單就會為true.  只要在表單中改變資料,都為null。

$pristine :  表單沒有填寫記錄, 就是沒有更改表單中資料 時, 為true , 一般是剛載入出來 改變資料時,

$valid

$invalid :  為null時,無效 , $invalid 為true

.$error.required

 

可以模仿使用:

<p>郵箱:<br>
  <input type="email" name="email" ng-model="email" required>
  <span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
  <span ng-show="myForm.email.$error.required">郵箱是必須的。</span>
  <span ng-show="myForm.email.$error.email">非法的郵箱。</span>
  </span>
</p>

8、AngularJS API:

全域API:

angular.lowercase() :  

angular.uppercase()

angular.isString():

angular.isNumber() : 判斷是否時數字

9、常識: (SSI: Server Side Includes, 伺服器端包含) 

AngularJS 包含: ng-include="‘html檔案路徑‘"

10、angularJS 也可以寫動畫, 利用css ,暫時不多做瞭解,用的少。

11、依賴注入(Dependency Injection,簡稱DI)是一種軟體設計模式,在這種模式下,一個或更多的依賴(或服務)被注入(或者通過引用傳遞)到一個獨立的對象(或用戶端)中,然後成為了該用戶端狀態的一部分。

AnJS 依賴注入核心組件:  [理解不夠透徹]

1、value  : JS 對象 , 用於向控制器傳遞值(注入到控制器中)

app.value("","")

2、factory : 是一個函數用於傳回值,常用來計算或傳回值, 在service 和 controller 需要時建立。

app.factory("Name",function(){});

3、provider 建立一個service , factory 等

app.config(function($provider){

  $provider.provider("NameService",function(){  /// provider 建立服務 

     this.$get = function(){      /// get方法, 建立一個factory,

    };  

  });

});

4、constant , 用來設定階段傳遞值

app.constant("", "");

PS: 使用$scope 雙向繫結model ,  可以在anjs中直接調用$scope變數, 也就是調用anjs函數可以不用傳值了。

 

12、AnJS 路由js檔案路徑 : http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js

$routeProvider 用來定義路由規則   ,,,       實現多視圖的單頁面訪問,在寫菜單url很有用。

app.config(["$routeProvider",function($routeProvider){

  $routeProvider

    .when(‘/‘,{template:"hssdffaffa"})

    .when()

    .otherwise({redirectTo:"/"});

}]);

 

來自http://www.cnblogs.com/generalLi/articles/5988096.html

angurlarjs學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.