Chrome开发者工具中的错误
Uncaught Error: [$injector:modulerr] Failed to instantiate module polmgr due to:
Error: [$injector:modulerr] Failed to instantiate module polmgr.controllers due to:
Error: [$injector:modulerr] Failed to instantiate module $http due to:
Error: [$injector:nomod] Module '$http' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
当我将$http添加到ioniframework中的模块时,就会出现此错误。我是noob。我已经在controllers.js文件中添加了$http,如果我删除所有内容,一切都会正常工作。但我需要打一个http get电话。
在下面找到controllers.js代码:-
angular.module('polmgr.controllers', ['$http'])
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
正确代码:-
angular.module('polmgr.controllers', [])
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
从外观上看,您试图错误地注入$http
服务。
它是angular.js/angular.min.js
提供的核心ng
模块的一部分。
因此,您不需要像下面这样将其添加为模块依赖项:
var ctrlModule = angular.module('polmgr.controllers', [..., '$http', ...])
相反,只需像对$scope
:那样将其注入控制器函数中即可
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});