Javascript 未捕获错误:[$injector:modulerr]未能实例化模块polmgr,原因是
Chrome开发者工具中的错误Javascript 未捕获错误:[$injector:modulerr]未能实例化模块polmgr,原因是,javascript,angularjs,ionic-framework,ionic,Javascript,Angularjs,Ionic Framework,Ionic,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
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.
当我在ionicframework中将$http添加到我的模块时,会出现此错误。
我是诺布。
我已经在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) {
});
这对我有用,谢谢