angularjs - 为什么会出现 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>
解决方案
angular.module
获取名称参数作为字符串:
var myCountrollers = angular.module('myCountrollers', []);
此外,您需要在模板中使用控制器的名称(而不是模块名称):
<body class="bg-secondary" ng-app="myApp" ng-controller="SearchCountroller">
推荐阅读
- javascript - 反应 useContext() 返回未定义
- python - 将网格上的人口转换为坐标,反之亦然
- javascript - 有没有办法自动为图像添加渐变?
- c# - ASP.NET 项目中的 JWT 身份验证
- javascript - TypeError: Object(...) is not a function error in useAccordianToggle
- lua - Roblox: clone an object in all players backpack lua
- prometheus - 增加舞会计数器的日期范围时,统计总计数减少
- javascript - 过滤掉嵌套对象并返回一个新对象
- javascript - 阅读更多按钮以显示成功付款消息的弹出窗口
- javascript - 如果用户选择验证码,如何删除验证码旁边的验证错误