Permalink
Fetching contributors…
Cannot retrieve contributors at this time
767 lines (757 sloc) 41.9 KB
---
redirect_from: /docs/1.0.10/interfaces/params.paramtypedefinition.html
---
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ParamTypeDefinition | @uirouter/angularjs</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/css/uirouter.css">
<script src="../assets/js/modernizr.js"></script>
<script src="../assets/js/reset.js"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="../assets/js/search.js" data-base="..">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">@uirouter/angularjs</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<!--
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
-->
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Internal UI-Router API</label>
<!--
<input type="checkbox" id="tsd-filter-only-exported" />
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
-->
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<li>
<a href="../index.html">@uirouter/angularjs</a>
</li>
<li>
<a href="../modules/params.html">params</a>
</li>
<li>
<a href="params.paramtypedefinition.html">ParamTypeDefinition</a>
</li>
</ul>
<h1>Interface ParamTypeDefinition</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Describes a custom <a href="../classes/params.paramtype.html">ParamType</a></p>
</div>
<p>See: <a href="../classes/url.urlmatcherfactory.html#type">UrlMatcherFactory.type</a></p>
<p>A developer can create a custom parameter type definition to customize the encoding and decoding of parameter values.
The definition should implement all the methods of this interface.</p>
<p>Parameter values are parsed from the URL as strings.
However, it is often useful to parse the string into some other form, such as:</p>
<ul>
<li>integer</li>
<li>date</li>
<li>array of <integer/date/string></li>
<li>custom object</li>
<li>some internal string representation</li>
</ul>
<p>Typed parameter definitions control how parameter values are encoded (to the URL) and decoded (from the URL).
UI-Router always provides the decoded parameter values to the user (from methods such as <a href="../classes/transition.transition-1.html#params">Transition.params</a>)).</p>
<p>For example, if a state has a url of <code>/foo/{fooId:int}</code> (the <code>fooId</code> parameter is of the <code>int</code> ParamType)
and if the browser is at <code>/foo/123</code>, then the 123 is parsed as an integer:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> fooId = transition.params().fooId;
fooId === <span class="hljs-string">"123"</span> <span class="hljs-comment">// false</span>
fooId === <span class="hljs-number">123</span> <span class="hljs-comment">// true</span>
</code></pre>
<h4 id="examples">Examples</h4>
<p>This example encodes an array of integers as a dash-delimited string to be used in the URL.</p>
<p>If we call <code>$state.go(&#39;foo&#39;, { fooIds: [20, 30, 40] });</code>, the URL changes to <code>/foo/20-30-40</code>.
If we navigate to <code>/foo/1-2-3</code>, the <code>foo</code> state&#39;s onEnter logs <code>[1, 2, 3]</code>.</p>
<pre><code>
$urlMatcherFactoryProvider.type(<span class="hljs-string">'intarray'</span>, {
<span class="hljs-comment">// Take an array of ints [1,2,3] and return a string "1-2-3"</span>
encode: <span class="hljs-function">(<span class="hljs-params">array</span>) =&gt;</span> array.join(<span class="hljs-string">"-"</span>),
<span class="hljs-comment">// Take an string "1-2-3" and return an array of ints [1,2,3]</span>
decode: <span class="hljs-function">(<span class="hljs-params">str</span>) =&gt;</span> str.split(<span class="hljs-string">"-"</span>).map(<span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> <span class="hljs-built_in">parseInt</span>(x, <span class="hljs-number">10</span>)),
<span class="hljs-comment">// Match the encoded string in the URL</span>
pattern: <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">"[0-9]+(?:-[0-9]+)*"</span>)
<span class="hljs-comment">// Ensure that the (decoded) object is an array, and that all its elements are numbers</span>
is: <span class="hljs-function">(<span class="hljs-params">obj</span>) =&gt;</span> <span class="hljs-built_in">Array</span>.isArray(obj) &amp;&amp;
obj.reduce(<span class="hljs-function">(<span class="hljs-params">acc, item</span>) =&gt;</span> acc &amp;&amp; <span class="hljs-keyword">typeof</span> item === <span class="hljs-string">'number'</span>, <span class="hljs-literal">true</span>),
<span class="hljs-comment">// Compare two arrays of integers</span>
equals: <span class="hljs-function">(<span class="hljs-params">array1, array2</span>) =&gt;</span> array1.length === array2.length &amp;&amp;
array1.reduce(<span class="hljs-function">(<span class="hljs-params">acc, item, idx</span>) =&gt;</span> acc &amp;&amp; item === array2[idx], <span class="hljs-literal">true</span>);
});
$stateProvider.state(<span class="hljs-string">'foo'</span>, {
<span class="hljs-attr">url</span>: <span class="hljs-string">"/foo/{fooIds:intarray}"</span>,
<span class="hljs-attr">onEnter</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">$transition$</span>) </span>{
<span class="hljs-built_in">console</span>.log($transition$.fooIds); <span class="hljs-comment">// Logs "[1, 2, 3]"</span>
}
});
</code></pre><p>This example decodes an integer from the URL.
It uses the integer as an index to look up an item from a static list.
That item from the list is the decoded parameter value.</p>
<pre><code>
<span class="hljs-keyword">var</span> <span class="hljs-keyword">list</span> = [<span class="hljs-string">'John'</span>, <span class="hljs-string">'Paul'</span>, <span class="hljs-string">'George'</span>, <span class="hljs-string">'Ringo'</span>];
$urlMatcherFactoryProvider.type(<span class="hljs-string">'listItem'</span>, {
encode: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(item)</span> </span>{
<span class="hljs-comment">// Represent the list item in the URL using its corresponding index</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">list</span>.indexOf(item);
},
decode: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(item)</span> </span>{
<span class="hljs-comment">// Look up the list item by index</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">list</span>[parseInt(item, <span class="hljs-number">10</span>)];
},
is: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(item)</span> </span>{
<span class="hljs-comment">// Ensure the item is valid by checking to see that it appears</span>
<span class="hljs-comment">// in the list</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">list</span>.indexOf(item) &gt; <span class="hljs-number">-1</span>;
}
});
$stateProvider.state(<span class="hljs-string">'list'</span>, {
url: <span class="hljs-string">"/list/{item:listItem}"</span>,
controller: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">($scope, $stateParams)</span> </span>{
console.log($stateParams.item);
}
});
<span class="hljs-comment">// ...</span>
<span class="hljs-comment">// Changes URL to '/list/3', logs "Ringo" to the console</span>
$state.go(<span class="hljs-string">'list'</span>, { item: <span class="hljs-string">"Ringo"</span> });
</code></pre><p>See: <a href="url.urlconfigapi.html#type">UrlConfigApi.type</a></p>
<dl class="tsd-comment-tags">
<dt>example</dt>
<dd></dd>
<dt>example</dt>
<dd></dd>
</dl>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
<li>
<span class="target">ParamTypeDefinition</span>
</li>
</ul>
</section>
<section class="tsd-panel">
<h3>Implemented by</h3>
<ul class="tsd-hierarchy">
<li><a href="../classes/params.paramtype.html" class="tsd-signature-type">ParamType</a></li>
</ul>
</section>
<section class="tsd-panel-group tsd-index-group">
<h2>Index</h2>
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
<section class="tsd-index-section ">
<h3>Properties</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#dynamic" class="tsd-kind-icon">dynamic</a></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#inherit" class="tsd-kind-icon">inherit</a></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#pattern" class="tsd-kind-icon">pattern</a></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#raw" class="tsd-kind-icon">raw</a></li>
</ul>
</section>
<section class="tsd-index-section ">
<h3>Methods</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-method tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#decode" class="tsd-kind-icon">decode</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#encode" class="tsd-kind-icon">encode</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#equals" class="tsd-kind-icon">equals</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><a href="params.paramtypedefinition.html#is" class="tsd-kind-icon">is</a></li>
</ul>
</section>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Properties</h2>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
<a name="dynamic" class="tsd-anchor"></a>
<!--
<h3><span class="tsd-flag ts-flagOptional">Optional</span> dynamic</h3>
-->
<div class="tsd-signature tsd-kind-icon">dynamic<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span> <div class="tsd-header">
<p> Dynamic flag </p>
</div>
</div>
<div class="tsd-declaration">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Dynamic flag</p>
</div>
<p>When <code>dynamic</code> is <code>true</code>, changes to the parameter value will not cause the state to be entered/exited.</p>
<p>Normally, if a parameter value changes, the state which declared that the parameter will be reloaded (entered/exited).
When a parameter is <code>dynamic</code>, a transition still occurs, but it does not cause the state to exit/enter.</p>
<p>Default: <code>false</code></p>
</div>
</div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L616">core/src/params/interface.ts:616</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
<a name="inherit" class="tsd-anchor"></a>
<!--
<h3><span class="tsd-flag ts-flagOptional">Optional</span> inherit</h3>
-->
<div class="tsd-signature tsd-kind-icon">inherit<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span> <div class="tsd-header">
<p> Enables/disables inheriting of parameter values (of this type) </p>
</div>
</div>
<div class="tsd-declaration">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Enables/disables inheriting of parameter values (of this type)</p>
</div>
<p>When a transition is run with <a href="transition.transitionoptions.html#inherit">TransitionOptions.inherit</a> set to
<code>true</code>, the current param values are inherited in the new transition.
However, parameters whose type has <code>inherit: false</code> set will <em>not be inherited</em>.</p>
<p>The internal parameter type of <code>hash</code> has <code>inherit: false</code>.
This is used to disable inheriting of the hash value (<code>#</code>) on subsequent transitions.</p>
<h4 id="example-">Example:</h4>
<pre><code class="lang-js">$state.go(<span class="hljs-string">'home'</span>, { <span class="hljs-string">'#'</span>: <span class="hljs-string">'inboxAnchor'</span> });
...
<span class="hljs-comment">// "#" is not inherited.</span>
<span class="hljs-comment">// The value of the "#" parameter will be `null`</span>
<span class="hljs-comment">// The url's hash will be cleared.</span>
$state.go(<span class="hljs-string">'home.nest'</span>);
</code></pre>
<hr>
<p>See also <a href="transition.transitionoptions.html#inherit">TransitionOptions.inherit</a> and <a href="params.paramdeclaration.html#inherit">ParamDeclaration.inherit</a></p>
</div>
</div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L604">core/src/params/interface.ts:604</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
<a name="pattern" class="tsd-anchor"></a>
<!--
<h3><span class="tsd-flag ts-flagOptional">Optional</span> pattern</h3>
-->
<div class="tsd-signature tsd-kind-icon">pattern<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">RegExp</span> <div class="tsd-header">
<p> A regular expression that matches the encoded parameter type </p>
</div>
</div>
<div class="tsd-declaration">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>A regular expression that matches the encoded parameter type</p>
</div>
<p>This regular expression is used to match an encoded parameter value <strong>in the URL</strong>.</p>
<p>For example, if your type encodes as a dash-separated numbers, match that here:
<code>new RegExp(&quot;[0-9]+(?:-[0-9]+)*&quot;)</code>.</p>
<p>There are some limitations to these regexps:</p>
<ul>
<li>No capturing groups are allowed (use non-capturing groups: <code>(?: )</code>)</li>
<li>No pattern modifiers like case insensitive</li>
<li>No start-of-string or end-of-string: <code>/^foo$/</code></li>
</ul>
</div>
</div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L563">core/src/params/interface.ts:563</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
<a name="raw" class="tsd-anchor"></a>
<!--
<h3><span class="tsd-flag ts-flagOptional">Optional</span> raw</h3>
-->
<div class="tsd-signature tsd-kind-icon">raw<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span> <div class="tsd-header">
<p> Disables url-encoding of parameter values </p>
</div>
</div>
<div class="tsd-declaration">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Disables url-encoding of parameter values</p>
</div>
<p>If a parameter type is declared <code>raw</code>, it will not be url-encoded.
Custom encoding can still be applied in the <a href="params.paramtypedefinition.html#encode">encode</a> function.</p>
<h3 id="decoding-warning">Decoding warning</h3>
<p>The decoding behavior of raw parameters is not defined.
See: <a href="params.paramdeclaration.html#raw">ParamDeclaration.raw</a> for details</p>
</div>
</div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L577">core/src/params/interface.ts:577</a></li>
</ul>
</aside>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Methods</h2>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
<a name="decode" class="tsd-anchor"></a>
<!--
<h3>decode</h3>
-->
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
<li class="tsd-signature tsd-kind-icon">decode<span class="tsd-signature-symbol">(</span>val<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, key<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span></li>
<li class="tsd-header">
<p> Decodes a parameter value string (from URL string or transition param) to a custom/native value. </p>
</li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Decodes a parameter value string (from URL string or transition param) to a custom/native value.</p>
</div>
<p>For example, if your type decodes to an array of ints, then decode the string as an array of ints here:</p>
<pre><code class="lang-js">decode: <span class="hljs-function">(<span class="hljs-params">str</span>) =&gt;</span> str.split(<span class="hljs-string">"-"</span>).map(<span class="hljs-function"><span class="hljs-params">str</span> =&gt;</span> <span class="hljs-built_in">parseInt</span>(str, <span class="hljs-number">10</span>))
</code></pre>
<p>Note: in general, <a href="params.paramtypedefinition.html#encode">encode</a> and <a href="params.paramtypedefinition.html#decode">decode</a> should be symmetrical. That is, <code>encode(decode(str)) === str</code></p>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>val <span class="tsd-signature-type">string</span></h5>
: <div class="tsd-comment tsd-typography">
<p>The URL parameter value to decode.</p>
</div>
</li>
<li>
<h5>key: <span class="tsd-flag ts-flagOptional">Optional</span>&nbsp; <span class="tsd-signature-type">string</span></h5>
: <div class="tsd-comment tsd-typography">
<p>The name of the parameter in which <code>val</code> is stored. Can be used for meta-programming of <code>ParamType</code> objects.</p>
</div>
</li>
</ul>
<div class="tsd-returns">
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">any</span></h4>
: <p>a custom representation of the URL parameter value.</p>
</div>
<hr>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L533">core/src/params/interface.ts:533</a></li>
</ul>
</aside> </li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
<a name="encode" class="tsd-anchor"></a>
<!--
<h3>encode</h3>
-->
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
<li class="tsd-signature tsd-kind-icon">encode<span class="tsd-signature-symbol">(</span>val<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, key<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string[]</span></li>
<li class="tsd-header">
<p> Encodes a custom/native type value to a string that can be embedded in a URL. </p>
</li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Encodes a custom/native type value to a string that can be embedded in a URL.</p>
</div>
<p>Note that the return value does <em>not</em> need to be URL-safe (i.e. passed through <code>encodeURIComponent()</code>).
It only needs to be a representation of <code>val</code> that has been encoded as a string.</p>
<p>For example, if your custom type decodes to an array of ints, then encode the array of ints to a string here:</p>
<pre><code class="lang-js">encode: <span class="hljs-function">(<span class="hljs-params">intarray</span>) =&gt;</span> intarray.join(<span class="hljs-string">"-"</span>)
</code></pre>
<p>Note: in general, <a href="params.paramtypedefinition.html#encode">encode</a> and <a href="params.paramtypedefinition.html#decode">decode</a> should be symmetrical. That is, <code>encode(decode(str)) === str</code></p>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>val <span class="tsd-signature-type">any</span></h5>
: <div class="tsd-comment tsd-typography">
<p>The value to encode.</p>
</div>
</li>
<li>
<h5>key: <span class="tsd-flag ts-flagOptional">Optional</span>&nbsp; <span class="tsd-signature-type">string</span></h5>
: <div class="tsd-comment tsd-typography">
<p>The name of the parameter in which <code>val</code> is stored. Can be used for meta-programming of <code>ParamType</code> objects.</p>
</div>
</li>
</ul>
<div class="tsd-returns">
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span>
<span class="tsd-signature-symbol"> | </span>
<span class="tsd-signature-type">string[]</span>
</h4>
: <p>a string representation of <code>val</code> that can be encoded in a URL.</p>
</div>
<hr>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L517">core/src/params/interface.ts:517</a></li>
</ul>
</aside> </li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
<a name="equals" class="tsd-anchor"></a>
<!--
<h3>equals</h3>
-->
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
<li class="tsd-signature tsd-kind-icon">equals<span class="tsd-signature-symbol">(</span>a<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, b<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
<li class="tsd-header">
<p> Determines whether two decoded values are equivalent. </p>
</li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Determines whether two decoded values are equivalent.</p>
</div>
<p>For example, if your type decodes to an array of ints, then check if the arrays are equal:</p>
<pre><code class="lang-js">equals: <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a.length === b.length &amp;&amp; a.reduce(<span class="hljs-function">(<span class="hljs-params">acc, x, idx</span>) =&gt;</span> acc &amp;&amp; x === b[idx], <span class="hljs-literal">true</span>)
</code></pre>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>a <span class="tsd-signature-type">any</span></h5>
: <div class="tsd-comment tsd-typography">
<p>A value to compare against.</p>
</div>
</li>
<li>
<h5>b <span class="tsd-signature-type">any</span></h5>
: <div class="tsd-comment tsd-typography">
<p>A value to compare against.</p>
</div>
</li>
</ul>
<div class="tsd-returns">
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
: <p><code>true</code> if the values are equivalent/equal, otherwise <code>false</code>.</p>
</div>
<hr>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L547">core/src/params/interface.ts:547</a></li>
</ul>
</aside> </li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
<a name="is" class="tsd-anchor"></a>
<!--
<h3>is</h3>
-->
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
<li class="tsd-signature tsd-kind-icon">is<span class="tsd-signature-symbol">(</span>val<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, key<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
<li class="tsd-header">
<p> Tests if some object type is compatible with this parameter type </p>
</li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Tests if some object type is compatible with this parameter type</p>
</div>
<p>Detects whether some value is of this particular type.
Accepts a decoded value and determines whether it matches this <code>ParamType</code> object.</p>
<p>If your custom type encodes the parameter to a specific type, check for that type here.
For example, if your custom type decodes the URL parameter value as an array of ints, return true if the
input is an array of ints:</p>
<pre><code>is: (<span class="hljs-keyword">val</span>) =&gt; <span class="hljs-type">Array</span>.isArray(<span class="hljs-keyword">val</span>) &amp;&amp; <span class="hljs-built_in">array</span>.reduce((acc, x) =&gt; acc &amp;&amp; parseInt(<span class="hljs-keyword">val</span>, <span class="hljs-number">10</span>) === <span class="hljs-keyword">val</span>, <span class="hljs-literal">true</span>)
</code></pre><p>If your type decodes the URL parameter value to a custom string, check that the string matches
the pattern (don&#39;t use an arrow fn if you need <code>this</code>): <code>function (val) { return !!this.pattern.exec(val) }</code></p>
<p>Note: This method is <em>not used to check if the URL matches</em>.
It&#39;s used to check if a <em>decoded value <em>is</em> this type</em>.
Use <a href="params.paramtypedefinition.html#pattern">pattern</a> to check the encoded value in the URL.</p>
<pre><code> <span class="hljs-keyword">this</span> <span class="hljs-keyword">is</span> the name <span class="hljs-keyword">of</span> the parameter <span class="hljs-keyword">in</span> which `<span class="javascript">val</span>` <span class="hljs-keyword">is</span> stored. Can be used <span class="hljs-keyword">for</span>
meta-programming <span class="hljs-keyword">of</span> `<span class="javascript">ParamType</span>` objects.
</code></pre>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>val <span class="tsd-signature-type">any</span></h5>
: <div class="tsd-comment tsd-typography">
<p>The value to check.</p>
</div>
</li>
<li>
<h5>key: <span class="tsd-flag ts-flagOptional">Optional</span>&nbsp; <span class="tsd-signature-type">string</span></h5>
: <div class="tsd-comment tsd-typography">
<p>If the type check is happening in the context of a specific <a href="../classes/url.urlmatcher.html">UrlMatcher</a> object,</p>
</div>
</li>
</ul>
<div class="tsd-returns">
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
: <p><code>true</code> if the value matches the type, otherwise <code>false</code>.</p>
</div>
<hr>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ui-router/core/blob/24da332/src/params/interface.ts#L497">core/src/params/interface.ts:497</a></li>
</ul>
</aside> </li>
</ul>
</section>
</section>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="../index.html"><em>@uirouter/angularjs</em></a>
</li>
<li class="label tsd-is-external">
<span>Public API</span>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/core.html">core</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/directives.html">directives</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/injectables.html">injectables</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/ng1.html">ng1</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/ng1_state_events.html">ng1_<wbr>state_<wbr>events</a>
</li>
<li class="current tsd-kind-external-module">
<a href="../modules/params.html">params</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/resolve.html">resolve</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/trace.html">trace</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/transition.html">transition</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/url.html">url</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/view.html">view</a>
</li>
<li class="label tsd-is-external">
<span>Internal UI-<wbr><wbr>Router API</span>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/common.html">common</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/common_hof.html">common_<wbr>hof</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/common_predicates.html">common_<wbr>predicates</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/common_strings.html">common_<wbr>strings</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/hooks.html">hooks</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/path.html">path</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/state.html">state</a>
</li>
<li class=" tsd-kind-external-module tsd-is-external">
<a href="../modules/vanilla.html">vanilla</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-enum tsd-parent-kind-external-module tsd-is-external">
<a href="../enums/params.deftype.html" class="tsd-kind-icon">Def<wbr>Type</a>
</li>
<li class=" tsd-kind-class tsd-parent-kind-external-module tsd-is-external">
<a href="../classes/params.param.html" class="tsd-kind-icon">Param</a>
</li>
<li class=" tsd-kind-class tsd-parent-kind-external-module tsd-is-external">
<a href="../classes/params.paramtype.html" class="tsd-kind-icon">Param<wbr>Type</a>
</li>
<li class=" tsd-kind-class tsd-parent-kind-external-module">
<a href="../classes/params.paramtypes.html" class="tsd-kind-icon">Param<wbr>Types</a>
</li>
<li class=" tsd-kind-class tsd-parent-kind-external-module tsd-is-external">
<a href="../classes/params.stateparams.html" class="tsd-kind-icon">State<wbr>Params</a>
</li>
<li class=" tsd-kind-interface tsd-parent-kind-external-module">
<a href="params.paramdeclaration.html" class="tsd-kind-icon">Param<wbr>Declaration</a>
</li>
</ul>
<ul class="current">
<li class="current tsd-kind-interface tsd-parent-kind-external-module">
<a href="params.paramtypedefinition.html" class="tsd-kind-icon">Param<wbr>Type<wbr>Definition</a>
<ul>
<li class=" tsd-kind-property tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#dynamic" class="tsd-kind-icon">dynamic</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#inherit" class="tsd-kind-icon">inherit</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#pattern" class="tsd-kind-icon">pattern</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#raw" class="tsd-kind-icon">raw</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#decode" class="tsd-kind-icon">decode</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#encode" class="tsd-kind-icon">encode</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#equals" class="tsd-kind-icon">equals</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface">
<a href="params.paramtypedefinition.html#is" class="tsd-kind-icon">is</a>
</li>
</ul>
</li>
</ul>
<ul class="after-current">
<li class=" tsd-kind-interface tsd-parent-kind-external-module">
<a href="params.rawparams.html" class="tsd-kind-icon">Raw<wbr>Params</a>
</li>
<li class=" tsd-kind-interface tsd-parent-kind-external-module tsd-is-external">
<a href="params.replace.html" class="tsd-kind-icon">Replace</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-external tsd-is-not-exported">
<a href="../modules/params.html#arraytype" class="tsd-kind-icon">Array<wbr>Type</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-external tsd-is-not-exported">
<a href="../modules/params.html#getreplace" class="tsd-kind-icon">get<wbr>Replace</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-external tsd-is-not-exported">
<a href="../modules/params.html#getsquashpolicy" class="tsd-kind-icon">get<wbr>Squash<wbr>Policy</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="http://typedoc.io" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="../assets/js/main.js"></script>
<script>if (location.protocol == 'file:') document.write('<script src="../assets/js/search.js"><' + '/script>');</script>
</body>
</html>