Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获错误:[$injector:modulerr]未能实例化模块polmgr,原因是_Javascript_Angularjs_Ionic Framework_Ionic - Fatal编程技术网

Javascript 未捕获错误:[$injector:modulerr]未能实例化模块polmgr,原因是

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

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.
当我在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) {
});

这对我有用,谢谢