Angularjs Routing $routeProvider

Source: Internet
Author: User

Angularjs Route Description: Define a routing rule (routeprovider) and then, through a different URL, tell (Ng-app) which page (HTML) to load and then render to (Ng-app) view (Ng-view).

Main interface index.html

<! DOCTYPE html>

<body>

<div ng-app= "Routeapp" >

<div ng-view></div><!--template will be added to this div--

</div>

<script src= "js/angular.min.js" ></script><!--load Angularjs Library--

<script src= "js/app.js" ></script><!--load App.js Library, define routing rules here--

<script src= "Js/main.js" ></script><!--define controller--

</body>

Defining Routing Rules app.js

var routeapp=angular.module ("Routeapp", []);

Routeapp.config (["$routeProvider", function ($routeProvider) {

$routeProvider. When ("/temp1", {

Templateurl:temp1/template1.html,

Controller: "MYCTRL1"

})

. When ("Temp2", {

Templateurl:temp2/template2.html,

Controller: "MyCtrl2"

}).

Otherwise ({

Redirectto: "/TEMP1";

});

}]);

Defining the Controller Main.js

Routeapp.controller ("MyCtrl1", ["$scope", function ($scope) {

Code

}])

. Controller ("MyCtrl2", ["$scope", function ($scope) {

Code

}]);

Defining Templates template1.html, template2.html

  

Angularjs Routing $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.