angular.isNumber
angular.isNumber: This function is used to check whether a string(reference) is number or not. The function isFunction will return true if passed reference is function else it will return false.
angular.isNumber – Check if string is number | Example
Sytax for angular.isElement is as below-
Syntax –
angular.isNumber Syntax
angular.isNumber(value); |
The above function checks whether the passed string(reference) is number or not.
Arguments
- value : This is reference to check.
Returns
- boolean : Returns true if reference is number else it will return false.
Now let us create a simple example to understand the above function.
Example
angular.isNumber – Validate number Example
<!DOCTYPE html> <html lang="en"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { var a = 'test'; var b = 10; $scope.result1 = ''; $scope.result2 = ''; $scope.chackVars = function() { if(angular.isNumber(a)){ $scope.result1 = 'Number'; }else{ $scope.result1 = 'Not a number'; } if(angular.isNumber(b)){ $scope.result2 = 'Number'; }else{ $scope.result2 = 'Not a number'; } } }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <button ng-click ="chackVars()" >Check Vars</button> <br> Result for a = {{result1}}<br> Result for b = {{result2}} </div> </div> </body> </html> |
If you run the above example it will produce the output something like this –
Advertisements
Add Comment
📖 Read More
- 1. angular.isObject
- 2. angular.isString
- 3. angular.isUndefined
- 4. angular.merge
- 5. a - Anchor Tag Directive