Type
object in module ui.router.util

Description

Implements an interface to define custom parameter types that can be decoded from and encoded to string parameters matched in a URL. Used by UrlMatcher objects when matching or formatting URLs, or comparing or validating parameter values.

See $urlMatcherFactory#type() for more information on registering custom types.

Usage

Type(config);

Parameters

ParamTypeDetails
configObject

A configuration object which contains the custom type definition. The object's properties will override the default methods and/or pattern in Type's public interface.

Returns

Object

Returns a new Type object.

Methods

Properties

Example

{
  decode: function(val) { return parseInt(val, 10); },
  encode: function(val) { return val && val.toString(); },
  equals: function(a, b) { return this.is(a) && a === b; },
  is: function(val) { return angular.isNumber(val) isFinite(val) && val % 1 === 0; },
  pattern: /\d+/
}