angular.isObject


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


angular.isObject – Check if Reference is object | Example

Sytax for angular.isObject is as below-

Syntax –

angular.isObject Syntax

angular.isObject(value);

The above function checks whether the passed string(reference) is isObject 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 object else it will return false.

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

Example

AngularJs check object type: Check If Object

<!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 = {name:'John'};
  $scope.result1 = '';
  $scope.result2 = '';
  $scope.chackObjects = function() {
    if(angular.isObject(a)){
		$scope.result1 = 'Object';
	}else{
		$scope.result1 = 'Not an Object';
  }
  if(angular.isObject(b)){
		$scope.result2 = 'Object';
	}else{
		$scope.result2 = 'Not an Object';
  }
  }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
    <button ng-click ="chackObjects()" >Check Objects</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 –

Note : Null s are not considered as object. JavaScript Arrays are object.

angular.isObject


Advertisements

Add Comment

📖 Read More