AngularJS – angular.is functions under the loop

AngularJS – angular.is functions under the loop

AngularJS – angular.is functions under the loop

AngularJS has a set of Built-in Functions that can be helpful while creating AngularJS applications.
In this blogpost we will have a closer look at the differen angular.is functions available in the core.

 

angular.isArray

Determines if a reference is an Array. Alias of Array.isArray.

 /*
  * angular.isArray
  * Determines if a reference is an Array. Alias of Array.isArray.
  */

  var _arr = ['creative','geeks','.com'];
  angular.isArray(_arr); // true
  angular.isArray(0); // false
  angular.isArray('http://www.creative-geeks.com'); // false

 

angular.isDate

Determines if a value is a date.

 /*
  * angular.isDate
  * Determines if a value is a date.
  */

  var _date = new Date();
  angular.isDate(_date); // true
  angular.isDate(0); // false
  angular.isDate('http://www.creative-geeks.com'); // false

 

angular.isDefined

Determines if a reference is defined.

 /*
  * angular.isDefined
  * Determines if a reference is defined.
  */

  angular.isDefined(0); // true
  angular.isDefined(undefined); // false

 

angular.isUndefined

Determines if a reference is undefined.

 /*
  * angular.isUndefined
  * Determines if a reference is undefined.
  */

  angular.isUndefined(0); // false
  angular.isUndefined(undefined); // true

 

angular.isElement

Determines if a reference is a DOM element (or wrapped jQuery element).

 /*
  * angular.isElement
  * Determines if a reference is a DOM element (or wrapped jQuery element).
  */

  angular.isElement(document.querySelector('#excistantID')); // true
  angular.isElement(document.querySelector('#nonExcistantID')); // false
  angular.isElement(undefined); // false

 

angular.isFunction

Determines if a reference is a Function.

 /*
  * angular.isFunction
  * Determines if a reference is a Function.
  */

  var _var = new Date();
  angular.isFunction(function(){}); // true
  angular.isFunction(undefined); // false
  angular.isFunction(_var); // false

 

angular.isNumber

Determines if a reference is a Number.
This includes the “special” numbers NaN, +Infinity and -Infinity

 /*
   * angular.isNumber
   * Determines if a reference is a Number.
   * This includes the "special" numbers NaN, +Infinity and -Infinity
   */

  angular.isNumber(5.25); // true
  angular.isNumber(NaN); // true
  angular.isNumber(true); // false
  angular.isNumber("5.25"); // false

 

angular.isObject

Determines if a reference is an Object.
Unlike typeof in JavaScript, nulls are not considered to be objects.
Note that JavaScript arrays are objects.

 /*
  * angular.isObject
  * Determines if a reference is an Object.
  * Unlike typeof in JavaScript, nulls are not considered to be objects.
  * Note that JavaScript arrays are objects.
  */

  angular.isObject({}); // true
  angular.isObject([]); // true
  angular.isObject(5); // false
  angular.isObject(null); // false

 

angular.isString

Determines if a reference is a String.

 /*
  * angular.isString
  * Determines if a reference is a String.
  */

  angular.isString("5"); // true
  angular.isString([]); // false
  angular.isString(5); // false
  angular.isString(null); // false

 

JSFiddle example


About the Author

Daan is a Creative-Geek who loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com.