概述
单页应用现在越来越受欢迎。模拟单页应用程序行为的网站都能提供手机/平板电脑应用程序的感觉。Angular可以帮助我们轻松创建此类应用
简单应用
我们打算创建一个简单的应用,涉及主页,关于和联系我们页面。虽然Angular是为创建比这更复杂的应用而生的,但是本教程展示了许多我们在大型项目中需要的概念。
目标
虽然使用Javascript和Ajax可以实现上述功能,但是在我们的应用中,Angular可以使我们处理更容易。
文档结构
- - script.js
- - index.html
- - pages
- ----- home.html
- ----- about.html
- ----- contact.html
HTML页面
这一部分比较简单。我们使用Bootstrap和Font Awesome。打开你的index.html文件,然后我们利用导航栏,添加一个简单布局。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js">
<script src="script.js">
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-home"></i> Home</a></li>
<li><a href="#about"><i class="fa fa-shield"></i> About</a></li>
<li><a href="#contact"><i class="fa fa-comment"></i> Contact</a></li>
</ul>
</div>
</nav>
<div id="main">
<!-- angular templating -->
<!-- this is where content will be injected -->