AngularJS如何使用angular.isFunction()函数?用法示例

2021年4月2日12:29:32 发表评论 1,103 次浏览

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">
       lsbin
   </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

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: