ParamTypes | @uirouter/core
Options
Menu

Class ParamTypes

A registry for parameter types.

This registry manages the built-in (and custom) parameter types.

The built-in parameter types are:

To register custom parameter types, use UrlConfig.type, i.e.,

router.urlService.config.type(customType)

Hierarchy

  • ParamTypes

Index

Constructors

  • Returns ParamTypes


Properties

defaultTypes: any = pick(ParamTypes.prototype, ['hash','string','query','path','int','bool','date','json','any',])
any: ParamTypeDefinition

Built-in parameter type: any

Built-in parameter type: any

This parameter type is used by default for url-less parameters (parameters that do not appear in the URL). This type does not encode or decode. It is compared using a deep equals comparison.

Example:

This example defines a non-url parameter on a StateDeclaration.

.state({
  name: 'new',
  url: '/new',
  params: {
    inrepyto: null
  }
});
$state.go('new', { inreplyto: currentMessage });
bool: ParamTypeDefinition

Built-in parameter type: bool

Built-in parameter type: bool

This parameter type serializes true/false as 1/0

Example:

.state({
  name: 'inbox',
  url: '/inbox?{unread:bool}'
});
$state.go('inbox', { unread: true });

The URL will serialize to: /inbox?unread=1.

Conversely, if the url is /inbox?unread=0, the value of the unread parameter will be a false.

date: ParamTypeDefinition

Built-in parameter type: date

Built-in parameter type: date

This parameter type can be used to serialize Javascript dates as parameter values.

Example:

.state({
  name: 'search',
  url: '/search?{start:date}'
});
$state.go('search', { start: new Date(2000, 0, 1) });

The URL will serialize to: /search?start=2000-01-01.

Conversely, if the url is /search?start=2016-12-25, the value of the start parameter will be a Date object where:

  • date.getFullYear() === 2016
  • date.getMonth() === 11 (month is 0-based)
  • date.getDate() === 25
hash: ParamTypeDefinition

Built-in parameter type: hash

Built-in parameter type: hash

This parameter type is used for the # parameter (the hash) It behaves the same as the string parameter type.

int: ParamTypeDefinition

Built-in parameter type: int

Built-in parameter type: int

This parameter type serializes javascript integers (numbers which represent an integer) to the URL.

Example:

.state({
  name: 'user',
  url: '/user/{id:int}'
});
$state.go('user', { id: 1298547 });

The URL will serialize to: /user/1298547.

When the parameter value is read, it will be the number 1298547, not the string "1298547".

json: ParamTypeDefinition

Built-in parameter type: json

Built-in parameter type: json

This parameter type can be used to serialize javascript objects into the URL using JSON serialization.

Example:

This example serializes an plain javascript object to the URL

.state({
  name: 'map',
  url: '/map/{coords:json}'
});
$state.go('map', { coords: { x: 10399.2, y: 49071 });

The URL will serialize to: /map/%7B%22x%22%3A10399.2%2C%22y%22%3A49071%7D

path: ParamTypeDefinition

Built-in parameter type: path

Built-in parameter type: path

This parameter type is the default type for path parameters. A path parameter is any parameter declared in the path portion of a url

  • /foo/:param1/:param2: two path parameters

This parameter type behaves exactly like the string type with one exception. When matching parameter values in the URL, the path type does not match forward slashes /.

Angular 1 note:

In ng1, this type is overridden with one that pre-encodes slashes as ~2F instead of %2F. For more details about this angular 1 behavior, see: https://github.com/angular-ui/ui-router/issues/2598

query: ParamTypeDefinition

Built-in parameter type: query

Built-in parameter type: query

This parameter type is the default type for query/search parameters. It behaves the same as the string parameter type.

A query parameter is any parameter declared in the query/search portion of a url

  • /bar?param2: a query parameter
string: ParamTypeDefinition

Built-in parameter type: string

Built-in parameter type: string

This parameter type coerces values to strings. It matches anything (new RegExp(".*")) in the URL

Methods

  • _flushTypeQueue(): void
  • Returns void


  • dispose(): void
  • Returns void


  • type(name: string, definition?: ParamTypeDefinition, definitionFn?: function): any
  • Registers a parameter type

Generated using TypeDoc