我嘗試使用最佳實踐代碼寫一個角度應用程序,我得到這樣的:角模塊錯誤
index.html文件包含:
<!DOCTYPE html>
<html ng-app='hrsApp'>
<head>
<title>Hrs app</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body ng-controller="homeCtrl">
<div class='container'>
<div ng-view></div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-route.min.js"></script>
<script src='app.js'></script>
<script src='js/controllers/homeCtrl.js'></script>
<script src='js/controllers/avCtrl.js'></script>
</body>
</html>
主文件:app.js:
angular.module('home', []);
angular.module('av', []);
// Declare app level module which depends on filters, and services
angular.module('hrsApp', [
'hrsApp.controllers',
'hrsApp.services',
'hrsApp.directives',
'hrsApp.filters',
// AngularJS
'ngRoute',
// All modules are being loaded here but EMPTY - they will be filled with controllers and functionality
'home',
'av'
]);
// configure our routes
angular.module('hrsApp').config([
'$routeProvider',
function ($routeProvider) {
'use strict';
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'views/home.html',
controller: 'homeCtrl'
})
// route for the about page
.when('/av', {
templateUrl: 'views/av.html',
controller: 'avCtrl'
})
// route for the contact page
.otherwise({
redirectTo: '/'
});
}
]);
然後我說家裏控制器:
/*global angular*/
angular.module('home').controller('homeCtrl', [
'$scope',
function ($scope) {
'use strict';
$scope._init = function() {
$scope.message = "welcome to Home Ctrl";
};
// DESTRUCTOR
$scope.$on('$destroy', function() {
});
// Run constructor
$scope._init();
$scope.log('info', '[HomeCtrl] initialized');
}
]);
和家庭的模板,暫時只包含一個綁定到消息變量:
<div>{{message}}</div>
當我嘗試運行我得到了應用程序:未捕獲的錯誤:[$注射器:modulerr] http://errors.angularjs.org/1.3.0/ $噴油器/ modulerr P0 = hrsApp & P1 =錯誤%3A%... googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0%2Fangular.min.js%3A18%3A3)angular.js:38
任何想法,我做錯了什麼?
你可以把完整的錯誤網址? (在瀏覽器中打開,然後ctrlc ctrlv) – 2014-10-26 15:19:04
只在'homeCtrl.js'和'avCtrl.js'後面包含'app.js' – Grundy 2014-10-26 15:23:23
您可以在其中定義下一個模塊:''hrsApp.controllers', 'hrsApp.services' , 「hrsApp.directives」, 「hrsApp.filters'' – Grundy 2014-10-26 15:29:03