W3cubDocs

/Angular.js 1.6

Improve this Doc ngRoute

Installation

First, get the file:

  • Google CDN e.g.
    "//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js"
  • NPM e.g.
    npm install --save angular-route@X.Y.Z
    or
    yarn add angular-route@X.Y.Z
  • Bower e.g.
    bower install angular-route#X.Y.Z
  • code.angularjs.org (discouraged for production use) e.g.
    "//code.angularjs.org/X.Y.Z/angular-route.js"

where X.Y.Z is the AngularJS version you are running.

Then, include angular-route.js in your HTML:

<script src="path/to/angular.js"></script>
<script src="path/to/angular-route.js"></script>

Finally, load the module in your application by adding it as a dependent module:

angular.module('app', ['ngRoute']);

With that you're ready to get started!

The ngRoute module provides routing and deeplinking services and directives for AngularJS apps.

See $route for an example of configuring and using ngRoute.

Module Components

Directive

Name Description
ngView

ngView is a directive that complements the $route service by including the rendered template of the current route into the main layout (index.html) file. Every time the current route changes, the included view changes with it according to the configuration of the $route service.

Provider

Name Description
$routeProvider

Used for configuring routes.

Service

Name Description
$route

$route 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.

$routeParams

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

© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.6.8/docs/api/ngRoute