$route
(service in module ng
)
Is used for deep-linking URLs to controllers and views (HTML partials).
It watches $location.url()
and tries to map the path to an existing route definition.
You can define routes through $routeProvider
's API.
The $route
service is typically used in conjunction with ngView
directive and the $routeParams
service.
Reference to the current route definition. The route definition contains:
controller
: The controller constructor as define in route definition.locals
: A map of locals which is used by $controller
service for
controller instantiation. The locals
contain
the resolved values of the resolve
map. Additionally the locals
also contain:
$scope
- The current route scope.$template
- The current route template HTML.Array of all configured routes.
Broadcasted if any of the resolve promises are rejected.
current – {Route} –
Current route information.
previous – {Route} –
Previous route information.
rejection – {Route} –
Rejection of the promise. Usually the error of the failed promise.
Broadcasted before a route change. At this point the route services starts
resolving all of the dependencies needed for the route change to occurs.
Typically this involves fetching the view template as well as any dependencies
defined in resolve
route property. Once all of the dependencies are resolved
$routeChangeSuccess
is fired.
next – {Route} –
Future route information.
current – {Route} –
Current route information.
Broadcasted after a route dependencies are resolved.
ngView
listens for the directive
to instantiate the controller and render the view.
current – {Route} –
Current route information.
previous – {Route} –
Previous route information.
The reloadOnSearch
property has been set to false, and we are reusing the same
instance of the Controller.
This example shows how changing the URL hash causes the $route
to match a route against the
URL, and the ngView
pulls in the partial.
Note that this example is using inlined templates
to get it working on jsfiddle as well.