当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


AngularJS angular.isUndefined()用法及代码示例


AngularJS中的angular.isUndefined()函数用于确定isUndefined函数内部的值是否未定义。如果引用未定义,则返回true,否则返回false。

用法:

angular.isUndefined( value )

返回值:如果传递的值不确定,则返回true,否则返回false。


例:本示例使用angular.isUndefined()函数确定isUndefined函数内部的值是否未定义。

<!DOCTYPE html> 
<html> 
    <head> 
        <title>angular.isUndefined() function</title> 
          
        <script src= 
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> 
        </script> 
    </head> 
   
    <body ng-app="app" style="text-align:center"> 
        <h1 style="color:green">GeeksforGeeks</h1> 
        <h2>angular.isUndefined()</h2> 
          
        <div ng-controller="isDefinedController"> 
            <b>Date:</b> {{date}}<br><br> 
                    {{isUndefined}} 
            <br><br><br> 
            <b>Date1:</b> {{date1}}<br><br> 
                            {{isUndefined1}} 
   
        </div> 
          
        <!-- Script to uses angular.isUndefined() function -->
        <script> 
            var app = angular.module("app", []); 
            app.controller('isDefinedController', 
                        ['$scope', function ($scope) { 
                $scope.date = new Date; 
                $scope.date1; 
                  
                $scope.isUndefined = angular.isUndefined($scope.date) 
                        == true ? "$scope.date is Undefined."  
                        :"$scope.date is not Undefined."; 
                  
                $scope.isUndefined1 = angular.isUndefined($scope.date1) 
                        == true ? "$scope.date1 is Undefined."  
                        :"$scope.date1 is not Undefined."; 
            }]); 
        </script> 
    </body> 
</html>

输出:
isUndefined



相关用法


注:本文由纯净天空筛选整理自Vishal Chaudhary 2大神的英文原创作品 AngularJS | angular.isUndefined() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。