AngularJS 1:$ injector:modulerr error
问题描述:
请帮我理解问题出在哪里。
HTML:
<!doctype html>
<html ng-app='ShoppingListCheckOff'>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/bootstrap.min.css">
<script src="angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div class="col-md-6" ng-controller='ToBuyController' >
</div>
<div class="col-md-6" ng-controller='AlreadyBoughtController' >
</div>
</body>
</html>
而这里的app.js
(function() {
'use strict';
angular.module('ShoppingListCheckOff', [])
.controller('ToBuyController', MyToBuyController);
.controller('AlreadyBoughtController', MyAlreadyBoughtController);
.service('ShoppingListCheckOffService', ShoppingListCheckOffService);
MyToBuyController.$inject = ['ShoppingListCheckOffService'];
function MyToBuyController($scope, $filter, $injector) {
}
}
/////////////
MyAlreadyBoughtController.$inject = ['ShoppingListCheckOffService'];
}
function ShoppingListCheckOffService() {
}
})();
和错误: angular.min.js:6未捕获的错误:[$注射器:modulerr] http://errors.angularjs.org/1.5.7/ $喷油器/ modulerr?P0 = ShoppingListCheckOf ...%20%20原子%20Bc的%20(HTTP%3A%2F%2Flocalhost%3A3000%2Fangular.min.js%3A21%3A163)(...)
非常感谢
答
在script.js文件中定义这两个控制器。
检查演示
(function() {
'use strict';
var app= angular.module('ShoppingListCheckOff', [])
app.controller("ToBuyController", function($scope) {
$scope.msg ="ToBuyController";
});
app.controller("AlreadyBoughtController", function($scope) {
$scope.msg ="AlreadyBoughtController";
});
})();
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
</head>
<body ng-app="ShoppingListCheckOff">
<div class="col-md-6" ng-controller='ToBuyController' >
{{msg}}
</div>
<div class="col-md-6" ng-controller='AlreadyBoughtController' >
{{msg}}
</div>
</body>
</html>
发表您的控制器使用 – Sajeetharan
角非精缩版,你就会有更清晰的错误信息,然后就可以张贴在这里。缩小版本用于生产,而不是开发。 –
这就是说,MyToBuyController和MyAlreadyBoughtController没有在app.js中定义 –