$routeProvider 路由

来源:互联网 发布:淘宝客博客网站源码 编辑:程序博客网 时间:2024/06/06 07:36
<head>
<meta charset="UTF-8">
<title></title>
<script src="libs/angular.min.js"></script>
<script src="libs/angular-route.js"></script>
<script>
angular.module("myApp",["ngRoute"]).config(function($routeProvider){
//when  : 路径名 /index; 路径规则
$routeProvider.when("/:type",{
templateUrl:"gequ.html" , //视图名称
controller:"demoC"        //控制器
})
}).controller("demoC",function($scope,$routeParams){
console.log("歌曲类型", $routeParams.type);
//http://127.0.01:8080/stu?type=2

if($routeParams.type==1){
$scope.datas=["丑八怪","土耳其"];
}else if($routeParams.type==2){
$scope.datas=["难忘今宵","贝多芬"];
}else if($routeParams.type==3){
$scope.datas=["一人饮酒醉","昨日帝王篇"];
}
})
</script>
</head>
<body ng-app="myApp">
<nav>
<a href="#/1">流行歌曲</a>
<a href="#/2">古典歌曲</a>
<a href="#/3">嘻哈歌曲</a>
<a href="#/4">轻音乐曲</a>
</nav>
<!--使用ng-veiew显示标签内容 -->
<div ng-view></div>
</body>

</html>


----------------------------------------------------------------------------------------------------------------------------------------------

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="libs/angular.min.js"></script>
<script src="libs/angular-route.js"></script>
<script>
angular.module("myApp",["ngRoute"]).config(function($routeProvider){

$routeProvider.when("/index",{
template:"首页内容"
}).when("/news",{
template:"新闻"
})
.when("/zhibo",{

templateUrl:"views.html"
})
.otherwise({
});
redirectTo:"/news"
})

</script>
</head>
<body ng-app="myApp">
<nav>
<a href="#/index">首页</a>
<a href="#/news">新闻</a>
<a href="#/zhibo">直播</a>
</nav>
<!--根据路由配置,显示不同内容-->
<div ng-view></div>
</body>
</html>


原创粉丝点击