zoukankan      html  css  js  c++  java
  • AngularJS 工具方法以及AngularJS中使用jQuery

     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();  
  • 相关阅读:
    RFC-RTSP
    ISDN简记
    mysql:Cannot proceed because system tables used by Event Scheduler were found damaged at server start
    Linux下svn常用命令
    嵌入式开发者技能
    Lua和C的语法差别
    CubeMX使用及感受
    海康、大华IPC的rtsp格式
    环境小硕的转行之路-15-小作业、闭包、迭代器
    环境小硕的转行之路-14-动态传参、命名空间、nonlocal和global
  • 原文地址:https://www.cnblogs.com/minghui007/p/7194112.html
Copyright © 2011-2022 走看看