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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。