首页 > 解决方案 > 为什么会出现 Uncaught Error: [$injector:modulerr] 错误?

问题描述

我收到未捕获的错误:[$injector:modulerr]

将此作为错误参考

当我在 Angular js 中运行“SearchCountroller”控制器功能时。

角度js版本v1.5.8

应用程序.js

var myApp = angular.module('myApp', [

'ngRoute',

'myCountrollers'

]);



myApp.config(['$routeProvider',function($routeProvider){

$routeProvider

.when('/',{

templateUrl: 'js/portal/search.html',

controller:'SearchCountroller'

});

}]);

控制器.js

 var myCountrollers = angular.module(myCountrollers, []);



myCountrollers.controller('SearchCountroller', function MyController($scope,$http) {

$http.get('js/data.json').then(function(response) {

$scope.artists = response.data;

$scope.myartistOrder = 'name';

});

});

索引.html

<!-- script -->
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular/angular-route.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controller.js"></script>

<body class="bg-secondary" ng-app="myApp" ng-controller="myCountrollers">
<div ng-view></div>
</body>

标签: angularjs

解决方案


angular.module获取名称参数作为字符串:

var myCountrollers = angular.module('myCountrollers', []);

此外,您需要在模板中使用控制器的名称(而不是模块名称):

<body class="bg-secondary" ng-app="myApp" ng-controller="SearchCountroller">

推荐阅读