EVOLUTION-MANAGER
Edit File: $route.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ngRoute/route.js?message=docs($route)%3A%20describe%20your%20change...#L254' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ngRoute/route.js#L254' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">$route</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> <a href="api/ngRoute/provider/$routeProvider">- $routeProvider</a> </li> <li> - service in module <a href="api/ngRoute">ngRoute</a> </li> </ol> </header> <div class="api-profile-description"> <p><code>$route</code> is used for deep-linking URLs to controllers and views (HTML partials). It watches <code>$location.url()</code> and tries to map the path to an existing route definition.</p> <p>Requires the <a href="api/ngRoute"><code>ngRoute</code></a> module to be installed.</p> <p>You can define routes through <a href="api/ngRoute/provider/$routeProvider">$routeProvider</a>'s API.</p> <p>The <code>$route</code> service is typically used in conjunction with the <a href="api/ngRoute/directive/ngView"><code>ngView</code></a> directive and the <a href="api/ngRoute/service/$routeParams"><code>$routeParams</code></a> service.</p> </div> <div> <h2 id="dependencies">Dependencies</h2> <ul> <li><a href="api/ng/service/$location"><code>$location</code></a></li><li><a href="api/ngRoute/service/$routeParams"><code>$routeParams</code></a></li> </ul> <h2>Methods</h2> <ul class="methods"> <li id="reload"> <h3><p><code>reload();</code></p> </h3> <div><p>Causes <code>$route</code> service to reload the current route even if <a href="api/ng/service/$location">$location</a> hasn't changed.</p> <p>As a result of that, <a href="api/ngRoute/directive/ngView">ngView</a> creates new scope and reinstantiates the controller.</p> </div> </li> <li id="updateParams"> <h3><p><code>updateParams(newParams);</code></p> </h3> <div><p>Causes <code>$route</code> service to update the current URL, replacing current route parameters with those specified in <code>newParams</code>. Provided property names that match the route's path segment definitions will be interpolated into the location's path, while remaining properties will be treated as query params.</p> </div> <h4>Parameters</h4> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> newParams </td> <td> <a href="" class="label type-hint type-hint-object">Object</a> </td> <td> <p>mapping of URL parameter names to values</p> </td> </tr> </tbody> </table> </li> </ul> <h2>Events</h2> <ul class="events"> <li id="$routeChangeStart"> <h3>$routeChangeStart</h3> <div><p>Broadcasted before a route change. At this point the route services starts resolving all of the dependencies needed for the route change to occur. Typically this involves fetching the view template as well as any dependencies defined in <code>resolve</code> route property. Once all of the dependencies are resolved <code>$routeChangeSuccess</code> is fired.</p> <p>The route change (and the <code>$location</code> change that triggered it) can be prevented by calling <code>preventDefault</code> method of the event. See <a href="api/ng/type/$rootScope.Scope#$on"><code>$rootScope.Scope</code></a> for more details about event object.</p> </div> <div class="inline"> <h4>Type:</h4> <div class="type">broadcast</div> </div> <div class="inline"> <h4>Target:</h4> <div class="target">root scope</div> </div> </li> <li id="$routeChangeSuccess"> <h3>$routeChangeSuccess</h3> <div><p>Broadcasted after a route dependencies are resolved. <a href="api/ngRoute/directive/ngView">ngView</a> listens for the directive to instantiate the controller and render the view.</p> </div> <div class="inline"> <h4>Type:</h4> <div class="type">broadcast</div> </div> <div class="inline"> <h4>Target:</h4> <div class="target">root scope</div> </div> </li> <li id="$routeChangeError"> <h3>$routeChangeError</h3> <div><p>Broadcasted if any of the resolve promises are rejected.</p> </div> <div class="inline"> <h4>Type:</h4> <div class="type">broadcast</div> </div> <div class="inline"> <h4>Target:</h4> <div class="target">root scope</div> </div> </li> <li id="$routeUpdate"> <h3>$routeUpdate</h3> <div><p>The <code>reloadOnSearch</code> property has been set to false, and we are reusing the same instance of the Controller.</p> </div> <div class="inline"> <h4>Type:</h4> <div class="type">broadcast</div> </div> <div class="inline"> <h4>Target:</h4> <div class="target">root scope</div> </div> </li> </ul> <h2>Properties</h2> <ul class="properties"> <li id="current"> <h3><code>current</code></h3> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-object">Object</a></td> <td><p>Reference to the current route definition. The route definition contains:</p> <ul> <li><code>controller</code>: The controller constructor as define in route definition.</li> <li><p><code>locals</code>: A map of locals which is used by <a href="api/ng/service/$controller">$controller</a> service for controller instantiation. The <code>locals</code> contain the resolved values of the <code>resolve</code> map. Additionally the <code>locals</code> also contain:</p> <ul> <li><code>$scope</code> - The current route scope.</li> <li><code>$template</code> - The current route template HTML.</li> </ul> </li> </ul> </td> </tr> </table> </li> <li id="routes"> <h3><code>routes</code></h3> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-object">Object</a></td> <td><p>Object with all route configuration Objects as its properties.</p> </td> </tr> </table> </li> </ul> <h2 id="example">Example</h2><p>This example shows how changing the URL hash causes the <code>$route</code> to match a route against the URL, and the <code>ngView</code> pulls in the partial.</p> <p> <div> <a ng-click="openPlunkr('examples/example-$route-service')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-$route-service" name="$route-service" module="ngRouteExample" deps="angular-route.js" fixBase="true"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><div ng-controller="MainController"> Choose: <a href="Book/Moby">Moby</a> | <a href="Book/Moby/ch/1">Moby: Ch1</a> | <a href="Book/Gatsby">Gatsby</a> | <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> | <a href="Book/Scarlet">Scarlet Letter</a><br/> <div ng-view></div> <hr /> <pre>$location.path() = {{$location.path()}}</pre> <pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre> <pre>$route.current.params = {{$route.current.params}}</pre> <pre>$route.current.scope.name = {{$route.current.scope.name}}</pre> <pre>$routeParams = {{$routeParams}}</pre> </div></code></pre> </div> <div class="runnable-example-file" name="book.html" language="html" type="html"> <pre><code>controller: {{name}}<br /> Book Id: {{params.bookId}}<br /></code></pre> </div> <div class="runnable-example-file" name="chapter.html" language="html" type="html"> <pre><code>controller: {{name}}<br /> Book Id: {{params.bookId}}<br /> Chapter Id: {{params.chapterId}}</code></pre> </div> <div class="runnable-example-file" name="script.js" language="js" type="js"> <pre><code>angular.module('ngRouteExample', ['ngRoute']) .controller('MainController', function($scope, $route, $routeParams, $location) { $scope.$route = $route; $scope.$location = $location; $scope.$routeParams = $routeParams; }) .controller('BookController', function($scope, $routeParams) { $scope.name = "BookController"; $scope.params = $routeParams; }) .controller('ChapterController', function($scope, $routeParams) { $scope.name = "ChapterController"; $scope.params = $routeParams; }) .config(function($routeProvider, $locationProvider) { $routeProvider .when('/Book/:bookId', { templateUrl: 'book.html', controller: 'BookController', resolve: { // I will cause a 1 second delay delay: function($q, $timeout) { var delay = $q.defer(); $timeout(delay.resolve, 1000); return delay.promise; } } }) .when('/Book/:bookId/ch/:chapterId', { templateUrl: 'chapter.html', controller: 'ChapterController' }); // configure html5 to get links working on jsfiddle $locationProvider.html5Mode(true); });</code></pre> </div> <div class="runnable-example-file" name="protractor.js" type="protractor" language="js"> <pre><code>it('should load and compile correct template', function() { element(by.linkText('Moby: Ch1')).click(); var content = element(by.css('[ng-view]')).getText(); expect(content).toMatch(/controller\: ChapterController/); expect(content).toMatch(/Book Id\: Moby/); expect(content).toMatch(/Chapter Id\: 1/); element(by.partialLinkText('Scarlet')).click(); content = element(by.css('[ng-view]')).getText(); expect(content).toMatch(/controller\: BookController/); expect(content).toMatch(/Book Id\: Scarlet/); });</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-$route-service/index.html" name="example-$route-service"></iframe> </div> </div> </p> </div>