AngularJS $routeProvider

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.