AngularTS
    Preparing search index...

    Interface ParamTypeDefinition

    Describes a built-in [[ParamType]].

    Parameter values are parsed from the URL as strings. Typed parameter definitions control how built-in parameter values are encoded to the URL and decoded from the URL. The router always provides decoded parameter values to the user (from methods such as [[Transition.params]]).

    For example, if a state has a url of /foo/{fooId:int} (the fooId parameter is of the int ParamType) and if the browser is at /foo/123, then the 123 is parsed as an integer:

    var fooId = transition.params().fooId;
    fooId === "123" // false
    fooId === 123 // true
    interface ParamTypeDefinition {
        dynamic?: boolean;
        inherit?: boolean;
        pattern?: RegExp;
        raw?: boolean;
        decode(val: string, key?: string): unknown;
        encode(val: unknown, key?: string): string | string[];
        equals(a: unknown, b: unknown): boolean;
        is(val: unknown, key?: string): boolean;
    }
    Index

    Properties

    dynamic?: boolean

    Dynamic flag

    When dynamic is true, changes to the parameter value will not cause the state to be entered/exited.

    Normally, if a parameter value changes, the state which declared that the parameter will be reloaded (entered/exited). When a parameter is dynamic, a transition still occurs, but it does not cause the state to exit/enter.

    Default: false

    inherit?: boolean

    Enables/disables inheriting of parameter values (of this type)

    When a transition is run with [[TransitionOptions.inherit]] set to true, the current param values are inherited in the new transition. However, parameters whose type has inherit: false set will not be inherited.

    The internal parameter type of hash has inherit: false. This is used to disable inheriting of the hash value (#) on subsequent transitions.

    $state.go('home', { '#': 'inboxAnchor' });
    ...
    // "#" is not inherited.
    // The value of the "#" parameter will be `null`
    // The url's hash will be cleared.
    $state.go('home.nest');

    See also [[TransitionOptions.inherit]] and [[ParamDeclaration.inherit]]

    pattern?: RegExp

    A regular expression that matches the encoded parameter type

    This regular expression is used to match an encoded parameter value in the URL.

    For example, if your type encodes as a dash-separated numbers, match that here: new RegExp("[0-9]+(?:-[0-9]+)*").

    There are some limitations to these regexps:

    • No capturing groups are allowed (use non-capturing groups: (?: ))
    • No pattern modifiers like case insensitive
    • No start-of-string or end-of-string: /^foo$/
    raw?: boolean

    Disables url-encoding of parameter values

    If a parameter type is declared raw, it will not be url-encoded.

    The decoding behavior of raw parameters is not defined. See: [[ParamDeclaration.raw]] for details

    Methods

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

      For example, if your type decodes to an array of ints, then decode the string as an array of ints here:

      decode: (str) => str.split("-").map(str => parseInt(str, 10))
      

      Note: in general, [[encode]] and [[decode]] should be symmetrical. That is, encode(decode(str)) === str

      Parameters

      • val: string

        The URL parameter value to decode.

      • Optionalkey: string

        The name of the parameter in which val is stored. Can be used for meta-programming of ParamType objects.

      Returns unknown

      a custom representation of the URL parameter value.

    • Encodes a built-in/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 encoded as a string.

      Note: in general, [[encode]] and [[decode]] should be symmetrical. That is, encode(decode(str)) === str

      Parameters

      • val: unknown

        The value to encode.

      • Optionalkey: string

        The name of the parameter in which val is stored. Can be used for meta-programming of ParamType objects.

      Returns string | string[]

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

    • Determines whether two decoded values are equivalent.

      For example, if your type decodes to an array of ints, then check if the arrays are equal:

      equals: (a, b) => a.length === b.length && a.reduce((acc, x, idx) => acc && x === b[idx], true)
      

      Parameters

      • a: unknown

        A value to compare against.

      • b: unknown

        A value to compare against.

      Returns boolean

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

    • Tests if some object type is compatible with this parameter type

      Detects whether some value is of this particular type. Accepts a decoded value and determines whether it matches this ParamType object.

      Note: This method is not used to check if the URL matches. It's used to check if a decoded value is this type. Use [[pattern]] to check the encoded value in the URL.

      Parameters

      • val: unknown

        The value to check.

      • Optionalkey: string

        If the type check is happening in the context of a specific URL parameter, this is the name of the parameter in which val is stored. Can be used for meta-programming of ParamType objects.

      Returns boolean

      true if the value matches the type, otherwise false.