Type
ui.router.util
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.
Type(config);
Param | Type | Details |
---|---|---|
config | Object | A configuration object which contains the custom type definition. The object's
properties will override the default methods and/or pattern in |
Object | Returns a new |
Converts a parameter value (from URL string or transition param) to a custom/native value.
Param | Type | Details |
---|---|---|
val | string | The URL parameter value to decode. |
key | string | The name of the parameter in which |
* | Returns a custom representation of the URL parameter value. |
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.
Param | Type | Details |
---|---|---|
val | * | The value to encode. |
key | string | The name of the parameter in which |
string | Returns a string representation of |
Detects whether a value is of a particular type. Accepts a native (decoded) value
and determines whether it matches the current Type
object.
Param | Type | Details |
---|---|---|
val | * | The value to check. |
key | string | Optional. If the type check is happening in the context of a specific
|
Boolean | Returns |
The regular expression pattern used to match values of this type when coming from a substring of a URL.
{ 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+/ }