We can configure the routing mechanism of our application with the
$routeProvider
function. This can be done by adding each route through the when function, which maps the URL pattern to a configuration object. This object has the following information.
Property | Description |
---|
<applicationName> | This represents the module name of the application. |
<viewName> | This represent structure of the incoming request pattern. |
config() | This function configures the routing module for the incoming request. |
controller | This is the name of the controller that should be associated with the template |
templateUrl | This is the URL of the template that will be rendered by the ngView module |
resolve | This is the map of dependencies that should be resolved and injected inside the controller (optional) |
redirectTo | This is the redirected location |
when / otherwise | These are the associated clauses to redirect the request to the targeted HTML view. |
Syntax
var myApplication = angular.module("", ["ngRoute"]);
myApplication.config(function($routeProvider) {
$routeProvider.when('/viewName1', {
templateUrl: '/partial1.html'
});
$routeProvider.when('/viewName2', {
templateUrl: '/partial2.html'
});
$routeProvider.otherwise({
redirectTo: '/viewName1'
});
});