当前越来越多的大型网站采用框架结构设计,学习AngularJS组件化势在必行,下面为页面框架简单案例!
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/index.css">
<script src="js/angular-1.6.4/angular.min.js"></script>
<script src="js/app/index.js"></script>
</head>
<body>
<div class="container">
<page-header></page-header>
<page-slide></page-slide>
<div class="pageBody">
主要内容部分
</div>
<page-footer></page-footer>
</div>
</body>
</html>
主页面Html文档
*{
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
div.container{
width: 1000px;
margin: auto;
}
引入主页面css文件
var app=angular.module("myapp",[]);
app.component("pageHeader",{
templateUrl:"js/app/other/pageheader.html",
controller:function($scope){
}
});
app.component("pageSlide",{
templateUrl:"js/app/other/pageslide.html",
controller:function($scope){
}
});
app.component("pageFooter",{
templateUrl:"js/app/other/pagefooter.html",
controller:function($scope){
}
});
引入主页面js文件
通过主页面JS文件引入其他分页面Html页面
<div class="header-pageHeader">
页面头部
</div>
<style>
.header-pageHeader{
width: 100%;
height: 200px;
background: #00CC33;
color: orange;
}
</style>
<div class="slide-pageSlide">
侧边栏导航部分页面左侧导航 </div> <style> .slide-pageSlide{ width:200px; height: 500px; float: left; background: #2aabd2; color: #fff; } </style>
<div class="footer-pageFooter"> 页脚部分 </div> <style> .footer-pageFooter{ clear: both; width: 100%; height: 100px; background: #6ecbcc; color: #2aabd2; } </style>
页脚部分
一般分页面html和css样式写在一起,
方便后期维护更新
最终页面显示如下: