AngularJS 工具方法以及AngularJS中使用jQuery

來源:互聯網
上載者:User

標籤:lan   屬性   end   -name   targe   star   tle   attr   函數   

 1. AngularJS 工具方法,參考angularjs API https://docs.angularjs.org/api官方文檔

(1)angular.isArray(value) 判斷是否是數組,返回true/false

 

[html] view plain copy 
  1. <div ng-controller="firstController">{{isArray}}</div>  
[html] view plain copy 
  1. $scope.arr=[1,2,3];  
  2. $scope.isArray=angular.isArray($scope.arr);  

(2)angular.isDate(value) 判斷是否是日期類型,返回true/false

(3)angular.idDefined(value) 判斷是否被定義了,返回true/false

(4)angular.isElement(node) 判斷是否是DOM節點,返回true/false

(5)angular.isFunction(value) 判斷是否是Function類型,返回true/false

(6)angular.isNumber(value) 判斷是否是Number類型,其中包括NaN,Infinity和-Infinity,返回true/false

(7)angular.isObject(value) 判斷是否是Object類型,Array是Objct類型,Null不是Object類型,返回true/false

(8)angular.isString(value) 判斷是否是字串類型,返回true/false

(9)angular.uppercase(value) 轉換成大寫

[html] view plain copy 
  1. <div ng-controller="firstController">{{name1}}</div>  
[html] view plain copy 
  1. $scope.name=‘zhangsan‘;  
  2. $scope.name1=angular.uppercase($scope.name);  

(10)angular.lowercase(value) 轉換成小寫

 

(11)angular.equals(o1,o2) 判斷兩個字串是否相等,返回true/false

 

[html] view plain copy 
  1. <div ng-controller="firstController">{{eq}}</div>  
[html] view plain copy 
  1. $scope.a=‘111‘;  
  2. $scope.b=‘111‘;  
  3. $scope.eq=angular.equals($scope.a,$scope.b);  

(12)angular.extend(dst,src) 繼承關係,如下代碼所示,b繼承了a的屬性

 

[html] view plain copy 
  1. $scope.a={name:‘張三‘};  
  2. $scope.b={age:10};  
  3.   
  4. $scope.c=angular.extend($scope.b,$scope.a);  
  5.   
  6. console.log($scope.b);//{"age":10,"name":"張三"}  

(13)angular.fromJson(json) 還原序列化json字串,把json字串轉換成JavaScript Object對象

 

 

[html] view plain copy 
  1. var json = ‘{"name":"hello","age":"20"}‘;  
  2.   
  3. console.log(json);  
  4.   
  5. $scope.json=angular.fromJson(json);  
  6.   
  7. console.log($scope.json);  

 

(14)angular.toJson(obj,pretty) 格式化json字串

 

[html] view plain copy 
  1. var json = {"name":"hello","age":"20"};  
  2.   
  3. // console.log(json);  
  4. // $scope.json=angular.toJson(json);  
  5.   
  6. $scope.json=angular.toJson(json,true);  
  7.   
  8. console.log($scope.json);  


(15)angular.copy(source, [destination]) 如下代碼所示,把a複製給b

 

 

[html] view plain copy 
  1. $scope.a={name:‘張三‘};  
  2. $scope.b={age:10};  
  3.   
  4. $scope.c=angular.copy($scope.a,$scope.b);  
  5.   
  6. console.log($scope.a);  
  7. console.log($scope.b);  


(16)angular.forEach(obj, iterator, [context]) 

 

[html] view plain copy 
  1. var json = {"name":"hello","age":"20","sex":‘男‘};  
  2.   
  3. angular.forEach(json,function(val,key){  
  4.   
  5.       //console.log(val);  
  6.     console.log(key);  
  7. });  


 

[html] view plain copy 
  1. var json = {"name":"hello","age":"20","sex":‘男‘};  
  2.   
  3. var results=[];  
  4.   
  5. angular.forEach(json,function(val,key){  
  6.     //console.log(val);  
  7.     //console.log(key);  
  8.     this.push(key+‘--‘+val);  
  9. },results);  
  10.   
  11. console.log(results);  


 

(17)angular.bind(self, fn, args);綁定對象,作為函數的上下文

 

[html] view plain copy 
    1. var self={name:‘張三‘};  
    2.   
    3. var f=angular.bind(self,function(age){  
    4.   
    5.           $scope.info=this.name+‘ is ‘+age;  
    6.   
    7.           console.log($scope.info);  
    8. });  
    9. f(30);  
    10.   
    11. var f=angular.bind(self,function(age){  
    12.   
    13.     $scope.info=this.name+‘ is ‘+age;  
    14.   
    15.     console.log($scope.info);  
    16. },10);  
    17. f();  
  1.  

AngularJS 工具方法以及AngularJS中使用jQuery

聯繫我們

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