文字
分享

AngularJS: API: ngRoute/service/$routeParams


$routeParams

  1. - service in module ngRoute

The $routeParams service allows you to retrieve the current set of route parameters.

Requires the ngRoute module to be installed.

The route parameters are a combination of $location's search() and path(). The path parameters are extracted when the $route path is matched.

In case of parameter name collision, path params take precedence over search params.

The service guarantees that the identity of the $routeParams object will remain unchanged (but its properties will likely change) even when a route change occurs.

Note that the $routeParams are only updated after a route change completes successfully. This means that you cannot rely on $routeParams being correct in route resolve functions. Instead you can use $route.current.params to access the new route's parameters.

渚濊禆

  • $route

绀轰緥

1

2

3

4

5

6

<code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:inherit;padding:0px;color:inherit;background-color:transparent;white-space:pre-wrap;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;"><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(153, 153, 136);">// Given:</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 </span><span style="box-sizing:border-box;color:rgb(153, 153, 136);">// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 </span><span style="box-sizing:border-box;color:rgb(153, 153, 136);">// Route: /Chapter/:chapterId/Section/:sectionId</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 </span><span style="box-sizing:border-box;color:rgb(153, 153, 136);">//</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 </span><span style="box-sizing:border-box;color:rgb(153, 153, 136);">// Then</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 $routeParams </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">==></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">{</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">chapterId</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">:</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'1'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">,</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> sectionId</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">:</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'2'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">,</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> search</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">:</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'moby'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">}</span></code>


上一篇:ngRoute/service/$route下一篇:ngSanitize