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


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


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

用法:

angular.isNumber( value )

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


例:本示例使用angular.isNumber()函數確定給定輸入是否為數字。

<!DOCTYPE html> 
<html> 
    <head> 
        <title>angular.isNumber()</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.isNumber()</h2> 
  
        <div ng-controller="geek"> 
            <b>Input1:</b>  
            <span><code> 
                    123  
            </code></span> 
              
            <br> 
              
            <b>IsNumber:</b>{{isNumber1}}<br /><br><br> 
            <b>Input2:</b>  
            <code> 
                "geeksforgeeks" 
            </code> 
            <br> 
            <b>IsNumber:</b> {{isNumber2}} 
        </div> 
          
        <!-- Script to uses angular.isNumber() Function -->
        <script> 
            var app = angular.module("app", []); 
            app.controller('geek', ['$scope', function ($scope) { 
                var obj1 = 123; 
                var obj2 = "geeksforgeeks"; 
                $scope.isNumber1 = angular.isNumber(obj1); 
                $scope.isNumber2 = angular.isNumber(obj2); 
            }]); 
        </script> 
    </body> 
</html>                    

輸出:
isNumber



相關用法


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