106 lines
7.7 KiB
HTML
Executable file
106 lines
7.7 KiB
HTML
Executable file
<a href="http://github.com/angular/angular.js/tree/v1.2.0rc1/src/ngRoute/route.js#L19" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ngRoute/route.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$routeProvider</code>
|
||
<div><span class="hint">service in module <code ng:non-bindable="">ngRoute</code>
|
||
</span>
|
||
</div>
|
||
</h1>
|
||
<div><h2 id="Description">Description</h2>
|
||
<div class="description"><div class="ngroute-routeprovider-page"><p>Used for configuring routes. See <a href="api/ngRoute.$route">$route</a> for an example.</p>
|
||
<p>Requires the <a href="api/ngRoute"><code>ngRoute</code></a> module to be installed.</p>
|
||
</div></div>
|
||
<div class="member method"><h2 id="Methods">Methods</h2>
|
||
<ul class="methods"><li><h3 id="otherwise">otherwise(params)</h3>
|
||
<div class="otherwise"><div class="ngroute-routeprovider-otherwise-page"><p>Sets route definition that will be used on route change when no other route definition
|
||
is matched.</p>
|
||
</div><h5 id="parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>params</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="ngroute-routeprovider-otherwise-page"><p>Mapping information to be assigned to <code>$route.current</code>.</p>
|
||
</div></td></tr></tbody></table><h5 id="returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="ngroute-routeprovider-otherwise-page"><p>self</p>
|
||
</div></td></tr></table></div>
|
||
</li>
|
||
<li><h3 id="when">when(path, route)</h3>
|
||
<div class="when"><div class="ngroute-routeprovider-when-page"><p>Adds a new route definition to the <code>$route</code> service.</p>
|
||
</div><h5 id="parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>path</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="ngroute-routeprovider-when-page"><p>Route path (matched against <code>$location.path</code>). If <code>$location.path</code>
|
||
contains redundant trailing slash or is missing one, the route will still match and the
|
||
<code>$location.path</code> will be updated to add or drop the trailing slash to exactly match the
|
||
route definition.</p>
|
||
<ul>
|
||
<li><code>path</code> can contain named groups starting with a colon (<code>:name</code>). All characters up
|
||
to the next slash are matched and stored in <code>$routeParams</code> under the given <code>name</code>
|
||
when the route matches.</li>
|
||
<li><code>path</code> can contain named groups starting with a colon and ending with a star (<code>:name*</code>).
|
||
All characters are eagerly stored in <code>$routeParams</code> under the given <code>name</code>
|
||
when the route matches.</li>
|
||
<li><code>path</code> can contain optional named groups with a question mark (<code>:name?</code>).</li>
|
||
</ul>
|
||
<p>For example, routes like <code>/color/:color/largecode/:largecode*\/edit</code> will match
|
||
<code>/color/brown/largecode/code/with/slashs/edit</code> and extract:</p>
|
||
<ul>
|
||
<li><code>color: brown</code></li>
|
||
<li><code>largecode: code/with/slashs</code>.</li>
|
||
</ul>
|
||
</div></td></tr><tr><td>route</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="ngroute-routeprovider-when-page"><p>Mapping information to be assigned to <code>$route.current</code> on route
|
||
match.</p>
|
||
<p>Object properties:</p>
|
||
<ul>
|
||
<li><code>controller</code> – <code>{(string|function()=}</code> – Controller fn that should be associated with newly
|
||
created scope or the name of a <a href="api/angular.Module#controller"><code>registered controller</code></a>
|
||
if passed as a string.</li>
|
||
<li><code>controllerAs</code> – <code>{string=}</code> – A controller alias name. If present the controller will be
|
||
published to scope under the <code>controllerAs</code> name.</li>
|
||
<li><p><code>template</code> – <code>{string=|function()=}</code> – html template as a string or a function that
|
||
returns an html template as a string which should be used by <a href="api/ngRoute.directive:ngView">ngView</a> or <a href="api/ng.directive:ngInclude"><code>ngInclude</code></a> directives.
|
||
This property takes precedence over <code>templateUrl</code>.</p>
|
||
<p>If <code>template</code> is a function, it will be called with the following parameters:</p>
|
||
<ul>
|
||
<li><code>{Array.<Object>}</code> - route parameters extracted from the current
|
||
<code>$location.path()</code> by applying the current route</li>
|
||
</ul>
|
||
</li>
|
||
<li><p><code>templateUrl</code> – <code>{string=|function()=}</code> – path or function that returns a path to an html
|
||
template that should be used by <a href="api/ngRoute.directive:ngView">ngView</a>.</p>
|
||
<p>If <code>templateUrl</code> is a function, it will be called with the following parameters:</p>
|
||
<ul>
|
||
<li><code>{Array.<Object>}</code> - route parameters extracted from the current
|
||
<code>$location.path()</code> by applying the current route</li>
|
||
</ul>
|
||
</li>
|
||
<li><p><code>resolve</code> - <code>{Object.<string, function>=}</code> - An optional map of dependencies which should
|
||
be injected into the controller. If any of these dependencies are promises, they will be
|
||
resolved and converted to a value before the controller is instantiated and the
|
||
<code>$routeChangeSuccess</code> event is fired. The map object is:</p>
|
||
<ul>
|
||
<li><code>key</code> – <code>{string}</code>: a name of a dependency to be injected into the controller.</li>
|
||
<li><code>factory</code> - <code>{string|function}</code>: If <code>string</code> then it is an alias for a service.
|
||
Otherwise if function, then it is <a href="api/AUTO.$injector#invoke"><code>injected</code></a>
|
||
and the return value is treated as the dependency. If the result is a promise, it is resolved
|
||
before its value is injected into the controller. Be aware that <code>ngRoute.$routeParams</code> will
|
||
still refer to the previous route within these resolve functions. Use <code>$route.current.params</code>
|
||
to access the new route parameters, instead.</li>
|
||
</ul>
|
||
</li>
|
||
<li><p><code>redirectTo</code> – {(string|function())=} – value to update
|
||
<a href="api/ng.$location"><code>$location</code></a> path with and trigger route redirection.</p>
|
||
<p>If <code>redirectTo</code> is a function, it will be called with the following parameters:</p>
|
||
<ul>
|
||
<li><code>{Object.<string>}</code> - route parameters extracted from the current
|
||
<code>$location.path()</code> by applying the current route templateUrl.</li>
|
||
<li><code>{string}</code> - current <code>$location.path()</code></li>
|
||
<li><code>{Object}</code> - current <code>$location.search()</code></li>
|
||
</ul>
|
||
<p>The custom <code>redirectTo</code> function is expected to return a string which will be used
|
||
to update <code>$location.path()</code> and <code>$location.search()</code>.</p>
|
||
</li>
|
||
<li><p><code>[reloadOnSearch=true]</code> - {boolean=} - reload route when only $location.search()
|
||
changes.</p>
|
||
<p>If the option is set to <code>false</code> and url in the browser changes, then
|
||
<code>$routeUpdate</code> event is broadcasted on the root scope.</p>
|
||
</li>
|
||
<li><p><code>[caseInsensitiveMatch=false]</code> - {boolean=} - match routes without being case sensitive</p>
|
||
<p>If the option is set to <code>true</code>, then the particular route can be matched without being
|
||
case sensitive</p>
|
||
</li>
|
||
</ul>
|
||
</div></td></tr></tbody></table><h5 id="returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="ngroute-routeprovider-when-page"><p>self</p>
|
||
</div></td></tr></table></div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|