角度模块错误
Angular module error
我尝试使用最佳代码实践编写一个有角度的应用程序,结果是:
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>
当我尝试运行应用程序时,我得到了:未捕获错误:[$injector:modulerr]http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=hrsApp&p1=错误%3A%…googleapis.com%2Fajax%2Libs%2Angularjs%2F1.3.0%2Fangular.min.js%3A18%3A3)angular.js:38
知道我做错了什么吗?
从您的代码中,我可以看到您已经注入了未声明的模块。
为了做到这一点,您必须在代码中添加以下行:
angular.module('hrsApp.controllers',[]);
angular.module('hrsApp.services',[]);
angular.module('hrsApp.directives',[]);
angular.module('hrsApp.filters',[]);
相关文章:
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- 错误:$injector:modulerr模块错误(我的第一个SPA应用程序)
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- 因果报应-找不到模块:错误:无法解析模块'scs'
- 错误:找不到模块'/lib/cli'
- 错误:$injector:modulerr加载图像时模块处于角度
- 扩展错误es6类模块问题
- 获取错误模块“;反应”;找不到
- 未捕获错误:模块未自注册
- 错误:模块未自行注册
- 离子 + 火基,错误模块“火基”不可用
- 如何在angular js中包含模块以删除找不到的错误模块
- AngularJS错误:模块'ngResource'不可用!您要么拼错了模块名称,要么忘记加载它
- 未捕获错误:模块名称“”;twilio”;尚未加载
- Firebase, AngularFire错误:模块Firebase不可用
- 未捕获错误:模块名"gcm"尚未加载上下文:_.使用要求([])
- RequireJS定义了返回错误模块依赖的回调
- 绑定错误.模块没有自我注册
- 当我运行“npm run dev”时,出现错误:模块解析失败
- npm启动错误"模块未找到;错误:无法解析目录"