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
- $scope.test = angular.isArray(null);
- $scope.test = angular.isArray({});
- $scope.test = angular.isArray([1, 2, 3, 4, 5, 6]);
- $scope.test = angular.isArray(["J", "I", "G"]);
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
- var d = new Date('12/14/2015');
- angular.isDate(d);
- angular.isDate(d.toString());
isDefined
It determines whether passed reference is defined or not. It returns true if reference is defined.
Syntax
angular.isDefined(value); Example - var p;
- $scope.test = angular.isDefined(p); This return false
- p = 12;
- $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 - $scope.test = angular.isFunction(null);
- $scope.testFunction = function () { alert('Hi'); }
- $scope.test = angular.isDefined($scope.testFunction);
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 - $scope.test = angular.isNumber(NaN);
- $scope.test = angular.isNumber("12");
- $scope.test = angular.isNumber(15);
- $scope.test = angular.isNumber(16.5);
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
- $scope.test = angular.isObject(null);
- $scope.test = angular.isObject(12);
- $scope.test = angular.isObject({});
- $scope.test = angular.isObject({ l: 12 });
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 - $scope.test = angular.isString(null);
- $scope.test = angular.isString(12);
- $scope.test = angular.isString("12");
- $scope.test = angular.isString("Test");
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.