<!doctype html>
<meta charset= "UTF-8" >
<title> Route One </title>
<script type= "Text/javascript" src= "Angular.min.js" ></script>
<script type= "Text/javascript" src= "Angular-route.min.js" ></script>
<script type= "Text/javascript" >
Introducing Ngroute in [] in the module
var MyApp = angular.module (' myApp ', [' Ngroute '])
Introduction of $routeprovider in configuration
Myapp.config ([' $routeProvider ', function ($routeProvider) {
$routeProvider
//Determine the contents of the Ng-view view based on the hash value
//:num Gets the arguments passed over
. When ('/aaa/:num ', {
Template: ' <p> home content </p>{{name} ',
controller: ' One '
})
. When ('/bbb ', {
Template: ' <p> page one content </p>{{name} ',
controller: ' Both '
})
. When ('/ccc/:num ', {
Template: ' <p> page two of content </p>{{name} ',
controller: ' Three '
})
//Set default values
. Otherwise ({
redirectto: '/aaa '
});
}]);
Myapp.controller (' One ', [' $scope ', ' $location ', ' $routeParams ', function ($scope, $location, $routeParams) {
$scope. name= ' Hello ';
$scope. $location = $location;
//Can get parameters passed over
Console.log ($routeParams);
}]);
Myapp.controller (' Both ', [' $scope ', function ($scope) {
$scope. name= ' Hi ';
//$scope. $location = $location;
}]);
Myapp.controller (' Three ', [' $scope ', ' $routeParams ', function ($scope, $routeParams) {
$scope. name= ' Hello ';
//$scope. $location = $location;
Console.log ($routeParams);
}]);
</script>
<body ng-controller= ' one ' >
<a href= "" ng-click= ' $location. Path ("aaa/123") ' > Home </a>
<a href= "" ng-click= ' $location. Path ("BBB") ' > Page one </a>
<a href= "" ng-click= ' $location. Path ("ccc/333") ' > Page two </a>
<div ng-view></div>
</body>
This article is from the "12897581" blog, please be sure to keep this source http://12907581.blog.51cto.com/12897581/1933205
AngularJs (3)