1. 程式人生 > >angularjs-判斷類型函數

angularjs-判斷類型函數

angularjs

#angularjs判斷類型函數
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  <script src="js/angular.min.js"></script>
 </head>
 <body>
  <div ng-app="app" ng-controller="ctrl">

  </div>

  <script type="text/javascript"> 
   var m=angular.module(‘app‘,[]);
   m.controller(‘ctrl‘,[‘$scope‘,function($scope){
    
    //angular.isArray 判斷是否為數組
    console.log(‘angular.isArray([]):‘+angular.isArray([]))
    
    //angular.isDate 判斷是否為Data類型
    console.log(‘angular.isDate(new Date()):‘+angular.isDate(new Date()))
    
    //angular.isDefined和angular.isUndefined 判斷數據是否定義
    console.log(‘angular.isDefined("abcd"):‘+angular.isDefined("abcd"))
    console.log(‘angular.isDefined():‘+angular.isDefined())
    console.log(‘angular.isUndefined("abcd"):‘+angular.isUndefined("abcd"))
    console.log(‘angular.isUndefined():‘+angular.isUndefined())
    
    //angular.isFunction 判斷是否為函數
    console.log(‘angular.isFunction(function(){}):‘+angular.isFunction(function(){}))
    
    //angular.isNumber 判斷是否為數字
    console.log(‘angular.isNumber(1):‘+angular.isNumber(1))
    
    //angular.isString 判斷是否為字符串
    console.log(‘angular.isString("abcd"):‘+angular.isString(‘abcd‘))
    
    //angular.isObject() 判斷是否為對象
    console.log(‘angular.isObject({}):‘+angular.isObject({}))
    
    //angular.isElement() 判斷是否為dom元素
    console.log(‘angular.isElement(document.getElementsByTagName("body").item(0)):‘+angular.isElement(document.getElementsByTagName(‘body‘).item(0)))
    
    //angular.equals 判斷是否相等
    console.log(‘angular.equals(["abcd"],["abcd"]):‘+angular.equals(["abcd"],["abcd"]))
   }]); 
   
  </script>
 </body>
</html>


angularjs-判斷類型函數