當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


AngularJS angular.isFunction()用法及代碼示例


AngularJS中的angular.isFunction()函數用於確定isFunction函數中的參數是否為函數。如果引用是一個函數,則返回true,否則返回false。

用法:

angular.isFunction(value)

返回值:如果傳遞的值是一個函數,則返回true,否則返回false。


例:

<!DOCTYPE html> 
<html> 
  
<head> 
    <script src= 
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> 
    </script> 
    <title> 
      angular.isFunction() 
  </title> 
</head> 
  
<body ng-app="app"
      style="text-align:center"> 
    <h1 style="color:green"> 
      GeeksforGeeks 
  </h1> 
    <h2> 
      angular.isFunction() 
  </h2> 
  
    <body ng-app="app"> 
        <div ng-controller="geek"> 
            <b>Input1:</b> 
            <span> 
                 <code> 
                  obj = [ 
                   { name:"Abc"}, 
                   { name:"Xyz"} 
                   ]; 
                </code> 
                </span> 
            <br> 
            <b>IsFunction:</b> 
          {{isFunction1}} 
            <br /> 
            <br> 
            <br> 
            <b>Input2:</b> 
            <code> 
        var Add = function () { 
            return null; 
        }; 
        </code> 
            <br> 
            <b>IsFunction:</b> 
          {{isFunction2}} 
        </div> 
        <script> 
            var app =  
                angular.module("app", []); 
            app.controller('geek',  
                     ['$scope', function($scope) { 
                var obj = [{ 
                    name:"Abc" 
                }, { 
                    name:"Xyz" 
                }]; 
                var Add = function() { 
                    return null; 
                }; 
                $scope.isFunction1 =  
                  angular.isFunction(obj); 
                         
                $scope.isFunction2 =  
                  angular.isFunction(Add); 
            }]); 
        </script> 
    </body> 
  
</html>

輸出:
isFunction



相關用法


注:本文由純淨天空篩選整理自Vishal Chaudhary 2大神的英文原創作品 AngularJS | angular.isFunction() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。