1. 程式人生 > >【AngularJS】5.AngularJS 工具方法以及AngularJS中使用jQuery

【AngularJS】5.AngularJS 工具方法以及AngularJS中使用jQuery

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

<div ng-controller="firstController">{{isArray}}</div>
$scope.arr=[1,2,3];
$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) 轉換成大寫

<div ng-controller="firstController">{{name1}}</div>
 $scope.name='zhangsan';
 $scope.name1=angular.uppercase($scope.name);
(10)angular.lowercase(value) 轉換成小寫

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

<div ng-controller="firstController">{{eq}}</div>
$scope.a='111';
$scope.b='111';
$scope.eq=angular.equals($scope.a,$scope.b);

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

$scope.a={name:'張三'};
$scope.b={age:10};

$scope.c=angular.extend($scope.b,$scope.a);

console.log($scope.b);//{"age":10,"name":"張三"}
(13)angular.fromJson(json) 反序列化json字串,把json字串轉換成JavaScript Object物件
 var json = '{"name":"hello","age":"20"}';

 console.log(json);

 $scope.json=angular.fromJson(json);

 console.log($scope.json);

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

 var json = {"name":"hello","age":"20"};

 // console.log(json);
 // $scope.json=angular.toJson(json);

 $scope.json=angular.toJson(json,true);

 console.log($scope.json);

(15)angular.copy(source,[destination]) 如下程式碼所示,把a複製給b
              $scope.a={name:'張三'};
              $scope.b={age:10};

              $scope.c=angular.copy($scope.a,$scope.b);

              console.log($scope.a);
              console.log($scope.b);

(16)angular.forEach(obj, iterator,[context]) 
              var json = {"name":"hello","age":"20","sex":'男'};

              angular.forEach(json,function(val,key){

                    //console.log(val);
                  console.log(key);
              });

              var json = {"name":"hello","age":"20","sex":'男'};

              var results=[];

              angular.forEach(json,function(val,key){
                  //console.log(val);
                  //console.log(key);
                  this.push(key+'--'+val);
              },results);

              console.log(results);

(17)angular.bind(self, fn, args);繫結物件,作為函式的上下文

              var self={name:'張三'};

              var f=angular.bind(self,function(age){

                        $scope.info=this.name+' is '+age;

                        console.log($scope.info);
              });
              f(30);

              var f=angular.bind(self,function(age){

                  $scope.info=this.name+' is '+age;

                  console.log($scope.info);
              },10);
              f();