简体   繁体   English

错误:[$ injector:nomod]模块不可用

[英]Error: [$injector:nomod] Module is not available

I am trying to upload a file with progress bar but getting 2 errors constantly, no matter what i do 我正在尝试上传带有进度条的文件,但是无论我做什么,都会不断出现2个错误

1)module not defined and 2nd is [$injector:nomod] module not available. 1)模块未定义,第二个模块是[$ injector:nomod]模块不可用。

http://jsfiddle.net/3m75wqt1/ http://jsfiddle.net/3m75wqt1/

this is my controller 这是我的控制器

PageController.js PageController.js

var PageController = function ($scope, fileUpload ) {
angular.module('app', ['ngProgress'])
angular.module('app')
.controller('PageController', function ($scope) {
    //$scope.fileUpload = {};
});
PageController.$inject = ['$scope','ngProgress'];

}; };

I have done a lot of searching but unable to find the error. 我已经做了很多搜索,但是找不到错误。 any help would be appreciated... Thanks in advance 任何帮助将不胜感激...在此先感谢

First at all the module method shoud not be called inside of a controller, so this: 首先,不应在控制器内部调用模块方法,因此:

var PageController = function ($scope, fileUpload) {
    angular.module('app', ['ngProgress'])
    angular.module('app')
        .controller('PageController', function ($scope) {//I will replace this with PageController 
            //$scope.fileUpload = {};
        });
    PageController.$inject = ['$scope', 'ngProgress'];
};

shoud look more like this: 应该看起来像这样:

var PageController = function ($scope, fileUpload) {
};
PageController.$inject = ['$scope', 'ngProgress'];
angular.module('app', ['ngProgress'])
angular.module('app').controller('PageController', PageController);

i removed the function in your controller method and put your defined PageController at its place 我在您的控制器方法中删除了该函数,并将您定义的PageController放在了它的位置

The second thing is that you dont need to call the module method twice, the first one is already returning the module, so the best approach shoud look like this: 第二件事是您不需要两次调用module方法,第一个已经返回了模块,因此最好的方法应如下所示:

var PageController = function ($scope, fileUpload) {
};
PageController.$inject = ['$scope', 'ngProgress'];
angular.module('app', ['ngProgress']).controller('PageController', PageController);

And i personaly like the array notation more than this, so my favorite would look like this, but that is up to you: 而且我个人更喜欢数组符号,所以我最喜欢的样子是这样,但这取决于您:

angular.module('app', [
    'ngProgress'//this is a module dependency (its also createt with angular.module)
]).controller('PageController', [
    '$scope',
    'fileUpload',//this is a dependency for the controller (probably a service)
    function ($scope, fileUpload) {
    }
]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:[$ injector:nomod]模块“ nvd3”不可用 - Error: [$injector:nomod] Module 'nvd3' is not available Angular / Karma:错误:[$ injector:nomod]模块'模块'不可用 - Angular/Karma: Error: [$injector:nomod] Module 'module' is not available AngularJS:未捕获的错误:[$injector:nomod] 模块 _ 不可用! | 对模块的多次引用 - AngularJS: Uncaught Error: [$injector:nomod] Module _ is not available! | Multiple References to Module Angular JS错误:[$ injector:nomod]模块'portfolioMockupApp.services'不可用 - Angular JS Error: [$injector:nomod] Module 'portfolioMockupApp.services' is not available “错误:$ injector:nomod模块不可用” - “Error: $injector:nomod Module Unavailable” `[$$ jector:nomod]模块“ google-maps”不可用。 - `[$injector:nomod] Module 'google-maps' is not available` AngularJS:[$ injector:nomod]模块'uiRouter'不可用 - AngularJS: [$injector:nomod] Module 'uiRouter' is not available 我的控制台中的错误-[$ injector:modulerr]由于以下原因而无法实例化模块启动器:[$ injector:nomod]模块'starter'不可用 - Error in my console - [$injector:modulerr] Failed to instantiate module starter due to: [$injector:nomod] Module 'starter' is not available 错误:[$ injector:modulerr]由于以下原因而无法实例化模块myApp:[$ injector:nomod]模块'ui.bootstrap'不可用 - Error: [$injector:modulerr] Failed to instantiate module myApp due to: [$injector:nomod] Module 'ui.bootstrap' is not available $ injector:nomod模块'app'不可用! 仅Firefox - $injector:nomod Module 'app' is not available! Firefox Only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM