`$ injector:modulerr`在angularjs中导入子模块时

时间:2017-11-26 20:01:01

标签: javascript angularjs bower angularjs-module

使用AngularJS框架时,我在导入子模块时遇到了一些麻烦。

我创建了模块及其依赖项,检查了我的导入顺序,并在index.html $injector:modulerr标记中导入了js文件。

当我的服务器尝试渲染我的页面时,我得到app.js hmodule/ hmodule/helpermonkeys.js hmodule/services/monkeymessageservice.js hmodule/controllers/monkeycontroller.js

堆栈跟踪指向凉亭,但是我的所有凉亭组件都存在。

我不确定如何调试此问题。

我有目录结构:

var centroApp = angular.module("centroApp", ['ngRoute', ..., 'ngWebSocket', 'helpermonkeys'])

/app.js:

(function() {                                                                                                                                             
    'use strict';                                                                                                                                             
    angular.module('helpermonkeys', ['ngWebSocket', 'monkeyMessageService', 'monkeyController']);                                                    
})();     

/hmodule/hm.js

(function() {                                                                                                                                                 
    'use strict';                                                                                                                                             
    angular.module('helpermonkeys').factory('monkeyMessageService', ['ngWebSocket', monkeyMessageService]);                                                   

    function monkeyMessageService($websocket) {                                                                                                               
        var messageService = {                                                                                                                                
            connect: connect,                                                                                                                                 
            sendActuatorRequest: sendActuatorRequest,                                                                                                         
            sendDataRequest: sendDataRequest,                                                                                                                 
            sendCommandRequest: sendCommandRequest,                                                                                                           
            messages: []                                                                                                                                      
        }                                                                                                                                                     

        return messageService;   
        ...
})();  

/hmodule/services/monkeymessageservice.js

(function() {                                                                                                                                                 
    'use strict';                                                                                                                                             
    angular.module('helpermonkeys').controller('monkeyController', ['$scope', 'monkeyMessageService', monkeyController]); 
 ....
})();

/hmmodule/controllers/monekeycontroller.js

    <script src="/js/helpermonkeysmodule/helpermonkeys.js"></script>                                                                                          
    <script src="/js/helpermonkeysmodule/services/monkeymessageservice.js"></script>                                                                          
    <script src="/js/helpermonkeysmodule/controllers/monkeycontroller.js"></script>
    <script src="/js/app.js"></script>    

的index.html

Failed to instantiate module centroApp due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.5.9/$injector/modulerr?p0=h...)
    at https://localhost/bower_components/angular/angular.min.js:6:412
    at https://localhost/bower_components/angular/angular.min.js:40:292
    at q (https://localhost/bower_components/angular/angular.min.js:7:359)
    at g (https://localhost/bower_components/angular/angular.min.js:39:382)
    at https://localhost/bower_components/angular/angular.min.js:40:34
    at q (https://localhost/bower_components/angular/angular.min.js:7:359)
    at g (https://localhost/bower_components/angular/angular.min.js:39:382)
    at eb (https://localhost/bower_components/angular/angular.min.js:43:382)
    at c (https://localhost/bower_components/angular/angular.min.js:21:19)
    at Ic (https://localhost/bower_components/angular/angular.min.js:21:332

堆栈跟踪

https://docs.angularjs.org/error/$injector/modulerr?p0=helpermonkeys&p1=Error:%20%5B$injector:modulerr%5D%20http:%2F%2Ferrors.angularjs.org%2F1.5.9%2F$injector%2Fmodulerr%3Fp0%3DmonkeyMessageService%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.9%252F%2524injector%252Fnomod%253Fp0%253DmonkeyMessageService%250A%2520%2520%2520%2520at%2520https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A6%253A412%250A%2520%2520%2520%2520at%2520https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A25%253A235%250A%2520%2520%2520%2520at%2520b%2520(https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A24%253A282)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A25%253A20%250A%2520%2520%2520%2520at%2520https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A40%253A17%250A%2520%2520%2520%2520at%2520q%2520(https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A7%253A359)%250A%2520%2520%2520%2520at%2520g%2520(https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A39%253A382)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A40%253A34%250A%2520%2520%2520%2520at%2520q%2520(https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A7%253A359)%250A%2520%2520%2520%2520at%2520g%2520(https%253A%252F%252Flocalhost%252Fbower_components%252Fangular%252Fangular.min.js%253A39%253A382)%0A%20%20%20%20at%20https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:6:412%0A%20%20%20%20at%20https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:40:292%0A%20%20%20%20at%20q%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:7:359)%0A%20%20%20%20at%20g%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:39:382)%0A%20%20%20%20at%20https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:40:34%0A%20%20%20%20at%20q%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:7:359)%0A%20%20%20%20at%20g%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:39:382)%0A%20%20%20%20at%20https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:40:34%0A%20%20%20%20at%20q%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:7:359)%0A%20%20%20%20at%20g%20(https:%2F%2Flocalhost%2Fbower_components%2Fangular%2Fangular.min.js:39:382

错误网址:

final long changeTime = 5000L;
button.postDelayed(new Runnable() {
    @Override
    public void run() {
        // call your function here
    }
}, changeTime);

感谢@charlietfl指出可以在URL中找到有问题的文件,我将调查我的Messaging服务。

1 个答案:

答案 0 :(得分:0)

我的monkeymessageservice看起来有问题。问题是有点垃圾,问题是我缺乏经验:p。

作为参考,Angularjs返回的URL包括违规模块。