Determinate Function In AngularJS

Introduction

AngularJS has many built-in directives that are used to determine the reference. In this article we will discuss about determinate functions. AngularJS has the following directives to be used to determine the reference.

isArray

It determines whether passed reference is an array type or not. It returns true if value is array type.

Syntax

angular.isArray(value);

Example

  1. $scope.test = angular.isArray(null); //This return false  
  2. $scope.test = angular.isArray({}); //This return false  
  3. $scope.test = angular.isArray([1, 2, 3, 4, 5, 6]); //This return true  
  4. $scope.test = angular.isArray(["J""I""G"]); //This return true  
isDate

It determines whether passed value is a date type or not. It returns true if value is date type.

Syntax

angular.isDate(value);

Example
  1. var d = new Date('12/14/2015');  
  2. angular.isDate(d); //This return true  
  3. angular.isDate(d.toString());//This return false  
isDefined

It determines whether passed reference is defined or not. It returns true if reference is defined.

Syntax

angular.isDefined(value);

Example
  1. var p;  
  2. $scope.test = angular.isDefined(p); This return false  
  3. p = 12;  
  4. $scope.test = angular.isDefined(p); This return true  
isElement

It determines whether passed reference is a DOM element or not. This function returns true if reference is a DOM element.

Syntax

angular.isElement(value);

isFunction

It determines whether passed reference is a function or not. This function returns true if reference is function.

Syntax

angular.isFunction(value);

Example
  1. $scope.test = angular.isFunction(null); //This return false  
  2. $scope.testFunction = function () { alert('Hi'); }  
  3. $scope.test = angular.isDefined($scope.testFunction); // This return true  
isNumber

It determines whether passed reference is a number or not. This function returns true if reference is number.

Syntax:

angular.isNumber(value);

This function includes all number from +Infinity to -Infinity and special number "NaN".

Example
  1. $scope.test = angular.isNumber(NaN); // This return true  
  2. $scope.test = angular.isNumber("12"); // This return false  
  3. $scope.test = angular.isNumber(15); // This return true  
  4. $scope.test = angular.isNumber(16.5); // This return true  
isObject

It determines whether passed reference is an object or not. This function returns true if reference is an object. The "null" is not considered as object.

Syntax

angular.isObject(value);

Example
  1. $scope.test = angular.isObject(null); // This return false  
  2. $scope.test = angular.isObject(12); // This return false  
  3. $scope.test = angular.isObject({}); // This return true  
  4. $scope.test = angular.isObject({ l: 12 });// This return true  
isString

It determines whether passed reference is a string or not. This function returns true if reference is a string type.

Syntax

angular.isString(value);

Example
  1. $scope.test = angular.isString(null); // This return false  
  2. $scope.test = angular.isString(12); // This return false  
  3. $scope.test = angular.isString("12"); // This return true  
  4. $scope.test = angular.isString("Test");// This return true  
isUndefined

It determines whether passed reference is undefined. This function returns true if reference is undefined.

Syntax

angular.isUndefined(value);

Summary

This article is for helping us to learn various Determinate function in AngularJS.

 


Similar Articles