[英]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.