AngularJs中路由ngRoute的使用
程序员文章站
2022-03-10 18:15:14
...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/angular-route.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
* {
font-size: 13px;
color: #696969;
}
a {
text-decoration: none;
color: #696969;
}
#aa {
float: left;
margin-left: 100px;
}
span {
margin-right: 20px;
}
#big {
width: 1000px;
margin: 0 auto;
}
#right {
float: right;
margin-right: 100px;
}
#page {
width: 1000px;
height: 500px;
margin: 0 auto;
background-color: whitesmoke;
}
#head {
width: 1000px;
height: 40px;
line-height: 40px;
background-color: whitesmoke;
}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div id="big">
<div id="head">
<span id="aa">我的站点</span>
<div id="right">
<span>
<img src="img/1101140.jpg" width="15px"/>
<a href="#/home">主页</a>
</span>
<span>
<img src="img/1101140.jpg" width="15px"/>
<a href="#/about">关于我们</a>
</span>
<span>
<img src="img/1101140.jpg" width="15px"/>
<a href="#/contact">联系我们</a>
</span>
</div>
</div>
<!--
显示不同的url对应的内容
-->
<div id="page" ng-view></div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", ["ngRoute"]);
app.controller("myCtrl", function($scope) {
})
//配置路由
app.config(["$routeProvider", function($routeProvider) {
$routeProvider
.when("/contact", {
templateUrl: "contact.html"
})
.when("/about", {
templateUrl: "about.html"
})
.when("/home", {
templateUrl: "home.html"
})
.otherwise({
redirectTo: "/home"
});
}]);
</script>
</body>
</html>
上一篇: VUE——解决跳页面跳转后 新页面没有位于顶部的问题
下一篇: 浮动静态路由