用AngularJS路由实现web页面跳转
2018-02-26 09:19
591 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>路由</title>
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<!--引入路由文件-->
<script src="http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script>
<style>
li{
float: left;
margin-left: 25px;
list-style: none;
}
</style>
</head>
<body ng-app='routeDemo'>
<!--左边栏-->
<div id="navigator" style="width: 100%;display: inline-block;background-color: paleturquoise;height: 200px;">
<!--菜单-->
<ul>
<li><a href="#/home">首页</a></li>
<li><a href="#/woman">音乐</a></li>
<li><a href="#/man">游戏</a></li>
</ul>
</div>
<!--右边栏-->
<div style="width: 100%;display: inline-block;height: 400px;">
<div ng-view=""></div>
</div>
</body>
<script type="text/ng-template" id="index.home.html">
<h1>欢迎登陆八维在线首页</h1>
</script>
<script type="text/ng-template" id="index.woman.html">
<h1>这是音乐模板</h1>
</script>
<script type="text/ng-template" id="index.man.html">
<h1>这是游戏模板</h1>
</script>
<script type="text/javascript">
angular.module('routeDemo',['ngRoute'])
.controller('HomeController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('WomanController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('WomanController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('ManController',function ($scope,$route) {
$scope.$route = $route;
})
//配置$routeProvider用来定义路由规则
//$routeProvider为我们提供了when(path,object)& other(object)函数按顺序定义所有路由,函数包含两个参数:
//@param1:url或者url正则规则
//@param2:路由配置对象
.config(function($routeProvider){
$routeProvider.
when('/home',{
//templateURL:插入ng-view的HTML模板文件
templateUrl:'index.home.html',
controller:'HomeController'
}).
when('/woman',{
templateUrl:'index.woman.html',
controller:'WomanController'
}).
when('/man',{
templateUrl:'index.man.html',
controller:'ManController'
})
})
</script>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>路由</title>
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<!--引入路由文件-->
<script src="http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script>
<style>
li{
float: left;
margin-left: 25px;
list-style: none;
}
</style>
</head>
<body ng-app='routeDemo'>
<!--左边栏-->
<div id="navigator" style="width: 100%;display: inline-block;background-color: paleturquoise;height: 200px;">
<!--菜单-->
<ul>
<li><a href="#/home">首页</a></li>
<li><a href="#/woman">音乐</a></li>
<li><a href="#/man">游戏</a></li>
</ul>
</div>
<!--右边栏-->
<div style="width: 100%;display: inline-block;height: 400px;">
<div ng-view=""></div>
</div>
</body>
<script type="text/ng-template" id="index.home.html">
<h1>欢迎登陆八维在线首页</h1>
</script>
<script type="text/ng-template" id="index.woman.html">
<h1>这是音乐模板</h1>
</script>
<script type="text/ng-template" id="index.man.html">
<h1>这是游戏模板</h1>
</script>
<script type="text/javascript">
angular.module('routeDemo',['ngRoute'])
.controller('HomeController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('WomanController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('WomanController',function ($scope,$route) {
$scope.$route = $route;
})
.controller('ManController',function ($scope,$route) {
$scope.$route = $route;
})
//配置$routeProvider用来定义路由规则
//$routeProvider为我们提供了when(path,object)& other(object)函数按顺序定义所有路由,函数包含两个参数:
//@param1:url或者url正则规则
//@param2:路由配置对象
.config(function($routeProvider){
$routeProvider.
when('/home',{
//templateURL:插入ng-view的HTML模板文件
templateUrl:'index.home.html',
controller:'HomeController'
}).
when('/woman',{
templateUrl:'index.woman.html',
controller:'WomanController'
}).
when('/man',{
templateUrl:'index.man.html',
controller:'ManController'
})
})
</script>
</html>
相关文章推荐
- 用angularJS的路由实现页面的跳转并传参
- 用AngularJS路由实现web站点的页面
- AngularJS路由实现页面跳转实例
- AngularJS实现单一页面内设置跳转路由的方法
- angularjs路由跳转页面后刷新报404错误
- AngularJS路由之ui-router(四)$state.go页面跳转
- 在WEB-INF下实现jsp页面的跳转
- 在angularjs可实现页面跳转的各种方式
- 【javaweb:servlet】采用重定向实现页面跳转
- 如何使用 asp.net 4.0 新特性 路由功能 有助于seo优化 给一个 asp.net web项目(网站项目) 增加路由功能 ,继承,给根据路由生成的url的结尾,增加一个有利于seo优化的斜杠 /,跳转到一个路由生成的url页面
- AngularJS实现页面跳转后自动弹出对话框实例代码
- .net MVC与angularjs实现页面跳转的区别
- google tv上webview页面js实现焦点跳转
- [angularjs] 前端路由实现单页跳转
- web项目中实现页面跳转的两种方式
- AngularJS进阶(八)实现页面跳转并进行参数传递
- 一步一步实现web程序信息管理系统之二----后台框架实现跳转登陆页面
- AngularJS进阶(八)实现页面跳转并进行参数传递
- angularjs实现页面跳转并进行参数传递
- Java web开发实现页面跳转到前一页