0

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

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 Uncaught Error: [$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)(…)

非常感谢

4

1 回答 1

0

在您的 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>

于 2016-12-04T12:30:48.837 回答