Type | UI-Router
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Type

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.

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+/
}

Hierarchy

  • Type

Implements

Index

Constructors

  • Parameters

    • def: TypeDefinition
      :

      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 Type

    :

    a new Type object


Properties

name: string
pattern: RegExp
raw: boolean

Methods

  • $asArray(mode: any, isSearch: any): any
  • Wraps an existing custom Type as an array of Type, depending on 'mode'. e.g.:

    • urlmatcher pattern "/path?{queryParam[]:int}"
    • url: "/path?queryParam=1&queryParam=2
    • $stateParams.queryParam will be [1, 2] if mode is "auto", then
    • url: "/path?queryParam=1 will create $stateParams.queryParam: 1
    • url: "/path?queryParam=1&queryParam=2 will create $stateParams.queryParam: [1, 2]
  • Wraps an existing custom Type as an array of Type, depending on 'mode'. e.g.:

    • urlmatcher pattern "/path?{queryParam[]:int}"
    • url: "/path?queryParam=1&queryParam=2
    • $stateParams.queryParam will be [1, 2] if mode is "auto", then
    • url: "/path?queryParam=1 will create $stateParams.queryParam: 1
    • url: "/path?queryParam=1&queryParam=2 will create $stateParams.queryParam: [1, 2]

    Parameters

    • mode: any
    • isSearch: any

    Returns any


  • $normalize(val: any): any
  • Given an encoded string, or a decoded object, returns a decoded object

  • Given an encoded string, or a decoded object, returns a decoded object

    Parameters

    • val: any

    Returns any


  • $subPattern(): string
  • decode(val: string, key?: string): any
  • Converts a parameter value (from URL string or transition param) to a custom/native value.

  • Converts a parameter value (from URL string or transition param) to a custom/native value.

    Parameters

    • val: string
    • key Optional: string

    Returns any

    :

    a custom representation of the URL parameter value.


  • encode(val: any, key?: string): string | Array<string>
  • Encodes a custom/native type value to a string that can be embedded in a URL. Note that the return value does not need to be URL-safe (i.e. passed through encodeURIComponent()), it only needs to be a representation of val that has been coerced to a string.

  • Encodes a custom/native type value to a string that can be embedded in a URL. Note that the return value does not need to be URL-safe (i.e. passed through encodeURIComponent()), it only needs to be a representation of val that has been coerced to a string.

    Parameters

    • val: any
    • key Optional: string

    Returns string | Array<string>

    :

    a string representation of val that can be encoded in a URL.


  • equals(a: any, b: any): boolean
  • Determines whether two decoded values are equivalent.

  • Determines whether two decoded values are equivalent.

    Parameters

    • a: any
    • b: any

    Returns boolean

    :

    true if the values are equivalent/equal, otherwise false.


  • is(val: any, key?: string): boolean
  • Detects whether a value is of a particular type. Accepts a native (decoded) value and determines whether it matches the current Type object.

  • Detects whether a value is of a particular type. Accepts a native (decoded) value and determines whether it matches the current Type object.

    Parameters

    • val: any
    • key Optional: string

    Returns boolean

    :

    true if the value matches the type, otherwise false.


  • toString(): string

Generated using TypeDoc