angular.isString


angular.isString: This function is used to check whether a reference is string or not. The function isString will return true if passed reference is string else it will return false. Here in this tutorial we are going to explain how you can use this function to determine a string in AngularJs. You can use our online editor to edit and run the code online.


angular.isString – Check if Reference is String | Example

Sytax for angular.isString is as below-

Syntax –

angular.isString Syntax

angular.isString(value);

The above function checks whether the passed string(reference) is String or not and on the basis of that it returns true or false.

Arguments

  • value : This is reference to check.

Returns

  • boolean : Returns true if reference is String else it will return false.

Now let us create a simple example to understand the above function.

Example

AngularJs check string type: Check If String

<!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 = 'hi';
  var b = 100;
  $scope.result1 = '';
  $scope.result2 = '';
  $scope.chackStr = function() {
    if(angular.isString(a)){
		$scope.result1 = 'String';
	}else{
		$scope.result1 = 'Not a String';
  }
  if(angular.isString(b)){
		$scope.result2 = 'String';
	}else{
		$scope.result2 = 'Not a String';
  }
  }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
    <button ng-click ="chackStr()" >Check String</button>
	<br>
	Result for a = {{result1}}<br>
	Result for b = {{result2}}
</div> 
</div>
</body>  
</html>                                                                                                                                                                           

Try it »

If you run the above example it will produce the output something like this –

 angular.isString - check string type


Advertisements

Add Comment

📖 Read More