<!doctype html>
<html ng-app="HelloAngular">
<head>
<meta charset="utf-8">
</head>
<body>
<div ng-controller="helloNgCtrl">
<p>{{greeting.text}},Angular</p>
</div>
</body>
<script src="js/angular-1.3.0.js"></script>
<script src="NgModule1.js"></script>
</html>
NgModule1.jsjavascript
var helloModule=angular.module('HelloAngular', []);
helloModule.controller('helloNgCtrl', ['$scope', function($scope){
$scope.greeting = {
text: 'Hello'
};
}]);
package.json 配置文件(管理使用到了那些框架、插件等)html
{
"version": "0.0.0",
"private": true,
"name": "angular-recommended",
"description": "ng官方推薦的項目結構",
"license": "MIT",
"devDependencies": { "http-server": "^0.6.1", "bower": "^1.3.1" },
"scripts": { "postinstall": "bower install", "prestart": "npm install", "start": "http-server -p 8000" } }
index.htmljava
<!doctype html>
<html ng-app="bookStoreApp">
<head>
<meta charset="UTF-8">
<title>BookStore</title>
<script src="framework/1.3.0.14/angular.js"></script>
<script src="framework/1.3.0.14/angular-route.js"></script>
<script src="framework/1.3.0.14/angular-animate.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>
<script src="js/directives.js"></script>
</head>
<body>
<div ng-view>
</div>
</body>
</html>
bookList.htmlangularjs
<ul>
<li ng-repeat="book in books">
書名:{{book.title}} 做者:{{book.author}}
</li>
</ul>
hello.htmlweb
<p>{{greeting.text}},Angular</p>
app.jsnpm
var bookStoreApp = angular.module('bookStoreApp', [
'ngRoute', 'ngAnimate', 'bookStoreCtrls', 'bookStoreFilters',
'bookStoreServices', 'bookStoreDirectives'
]);
bookStoreApp.config(function($routeProvider) {
$routeProvider.when('/hello', {
templateUrl: 'tpls/hello.html',
controller: 'HelloCtrl'
}).when('/list',{
templateUrl:'tpls/bookList.html',
controller:'BookListCtrl'
}).otherwise({
redirectTo: '/hello'
})
});
controllers.jsjson
var bookStoreCtrls = angular.module('bookStoreCtrls', []);
bookStoreCtrls.controller('HelloCtrl', ['$scope',
function($scope) {
$scope.greeting = {
text: 'Hello'
};
}
]);
bookStoreCtrls.controller('BookListCtrl', ['$scope',
function($scope) {
$scope.books =[
{title:"《Ext江湖》",author:"大漠窮秋"},
{title:"《ActionScript遊戲設計基礎(第二版)》",author:"大漠窮秋"},
{title:"《用AngularJS開發下一代WEB應用》",author:"大漠窮秋"}
]
}
]);
/** * 這裏接着往下寫,若是控制器的數量很是多,須要分給多個開發者,能夠藉助於grunt來合併代碼 */
directvies.js服務器
var bookStoreDirectives = angular.module('bookStoreDirectives', []);
bookStoreDirectives.directive('bookStoreDirective_1', ['$scope',
function($scope) {}
]);
bookStoreDirectives.directive('bookStoreDirective_2', ['$scope',
function($scope) {}
]);
filters.js=app
var bookStoreFilters = angular.module('bookStoreFilters', []);
bookStoreFilters.filter('bookStoreFilter_1', ['$scope',
function($scope) {}
]);
bookStoreFilters.filter('bookStoreFilter_2', ['$scope',
function($scope) {}
]);
services.js框架
var bookStoreServices = angular.module('bookStoreServices', []);
bookStoreServices.service('bookStoreService_1', ['$scope',
function($scope) {}
]);
bookStoreServices.service('bookStoreService_2', ['$scope',
function($scope) {}
]);
路由的原理:首先分析下這個地址http://127.0.0.1:8080/app/#/hello
咱們發現這個地址中的#
的做用是:內部錨點,用來進行頁面內部的跳轉,加上這個#
後它不會像服務器進行提交請求。
那麼既然是頁面的內部跳轉,這個AngularJS就能夠捕獲這個跳轉從而經過定義路由規則進行頁面的渲染。