AngularJS Views and Bootstrap
Categories: Angular Angular JS
AngularJS Views and Bootstrap
We will now start a new AngularJS blog project that uses public REST services created especially for this book. We will work on the blog project for the rest of this book. You can also download the project code from GitHub. We will start off by building the views and the controllers for those views.
Twitter Bootstrap is a free collection of HTML and CSS templates. We will build the AngularJS views with the help of Twitter Bootstrap to help cut development time. Once we have the views and controllers in place and understand their operation.
AngularJS Templates
AngularJS views are defined by building templates (partials). Views in AngularJS are composed of HTML code with directives added, such as the ng-model directive shown previously. AngularJS builds the views dynamically at runtime by merging the templates with the properties passed to the templates in the $scope object. The end result is pure HTML code bound to the ng-view directive.
Creating the Blog Project
Start a new HTML5 project in NetBeans and call it AngularJsBlog. Set up the folder structure. Move the downloaded AngularJS, jQuery, and Bootstrap library files to the js/libs folder, as shown.
Creating the Blog Project
Start a new HTML5 project in NetBeans and call it AngularJsBlog. Set up the folder structure Move the downloaded AngularJS, jQuery, and Bootstrap library files to the js/libs folder, as shown.
We’ll begin with the code for the index.html file. As you can see, we load the needed library files with the <script> tag in the <head> section of the page. The tag <div ngview></div> is where all dynamic content is inserted. As the user clicks on links in the application, existing content attached to the tag is removed and new dynamic content is then attached to that same tag:
<!-- chapter5/index.html -->
<!DOCTYPE html>
<html lang="en" ng-app="blogApp">
<head>
<title>AngularJS Blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta data-fr-http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="js/libs/jquery-1.10.2.min.js"></script>
<script src="js/libs/angular.min.js"></script>
<script src="js/libs/angular-route.min.js"></script>
<script src="js/libs/angular-resource.min.js"></script>
<script src="js/libs/angular-cookies.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</head>
<body>
<div ng-view></div>
</body>
</html>