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 添加到 ionicframework 中的模块时,会出现此错误。 我是菜鸟。 我已经在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) {
});
最佳答案
从表面上看,您尝试错误地注入(inject) $http
服务。
它是 ng
核心模块的一部分,由 angular.js/angular.min.js
提供。
因此,您不需要将其添加为模块依赖项,如下所示:
var ctrlModule = angular.module('polmgr.controllers', [..., '$http', ...])
相反,只需将其注入(inject) Controller 函数中,就像对 $scope
所做的那样:
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
关于javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module polmgr due to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29185073/