The pseudo-code on the O ' Reilly book
var somemodule = angular.module (' somemodule ', [... module dependencies]); Somemodule.config ( function($routeProvider) { $routeProvider . When (' url ', {controller:acontroller, Templateurl : '/path/to/template '}) . When (...) // Other mappings for your app . otherwise (...) // What to does if nothing else matches});
The $route is used for URLs to the link between the controller and the view (HTML template), which monitors $location.url () and attempts to map the path and its corresponding routing configuration, which needs to be injected with the installation Ngroute module.
var somemodule = angular.module (' Somemodule ', [' Ngroute ']);
Give me a detailed chestnut.
varApp = Angular.module (' app ', [' Ngroute ']); App. Config (function($routeProvider) {$routeProvider. When ('/other ', {controller:' Otherctrl ', Templateurl:' Content/views/other.html ', publicaccess:true}). When (‘/‘, {controller:' Homectrl ', Templateurl:' Content/views/home.html '}). When ('/other/:id ', {controller:' Otherdetailctrl ', Templateurl:' Content/views/otherdetail.html ', publicaccess:true}). Otherwise ({redirectto:‘/‘ }); }app.controller (' Homectrl ',function($scope, $http) {Console.log (' I am home page '); $scope. Title= ' I am home page ';}); App.controller (' Otherctrl ',function($scope) {Console.log (' I am other page '); $scope. Title= ' I am other page ';}); App.controller (' Otherdetailctrl ',function($scope, $routeParams, $location) {varID =$routeParams. ID; if(id = = 0{$location. Path ('/other '); } console.log (' I am otherdetailctrl page '); $scope. Title= ' I am Otherdetailctrl page ';});
In $route (routing), two dependency services are provided: $location, $routeParams.
$location, $routeParams can be used in the controller, such as the Otherdetailctrl, can be obtained through the $routeparams routing parameters, can be routed through the $location to jump.
AngularJS $routeProvider