【问题标题】:AngularJS 1: $injector:modulerr errorAngularJS 1: $injector:modulerr 错误
【发布时间】:2016-12-04 12:25:08
【问题描述】:

请帮助我了解问题出在哪里。

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 未捕获的错误:[$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=ShoppingListCheckOf...%20%20at%20Bc%20(http%3A%2F%2Flocalhost%3A3000%2Fangular.min .js%3A21%3A163)(…)

非常感谢

【问题讨论】:

  • 发布你的控制器
  • 使用非缩小版的 Angular,你会得到更清晰的错误信息,然后你可以在这里发布。缩小版用于生产,而非开发。
  • 也就是说,MyToBuyController 和 MyAlreadyBoughtController 没有在 app.js 中定义
  • 你JS错了,不管角度。您不能以; 结束一行,然后像链接方法一样使用.controller

标签: angularjs angularjs-injector


【解决方案1】:

在您的 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="angular.js@1.4.7" 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>

【讨论】:

    猜你喜欢
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2016-03-12
    • 2015-08-21
    • 1970-01-01
    相关资源
    最近更新 更多