javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module polmgr due to

标签 javascript angularjs ionic-framework

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/

相关文章:

javascript 数组返回 [object Window] 而不是数组内容

javascript - JS 圆环图/百分比乱序

javascript - 比较 2 个对象数组。按 ids 匹配,将对象属性插入数组

javascript - 简单的knockout.js 不起作用

angularjs - 在 AWS EC2 服务器上托管 Angular 应用程序、ExpressJS 端点

css - 如何在 Ionic 3 的 ion-navbar 中内联按钮和 ion-title?

android - Ionic 5 将 Android minSdkVersion 从 21 更改为版本 23

angularjs - 在执行 Controller 之前让 AngularJS 编译指令和链接函数

javascript - $q : default reject handler

ios - ionic $http.post 在模拟器中失败,但在浏览器和 iPhone 中有效