繁体   English   中英

angularjs奇怪的错误加载控制器

[英]angularjs weird error loading controllers

在过去的几个月中,我一直在开发angularjs,并且我有一个带有一些控制器,指令和服务的应用程序。 到现在为止一切都很好,但是使用最后一个控制器,我遇到了一个奇怪的错误,那就是我发疯了。 因为该应用程序的大小足以将所有代码放到这里,所以我将其中的重要部分放到了这里。

在我的index.html中

<!DOCTYPE html>
<html ng-app="my_app">
<head>
    <meta charset="encoding">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <meta name="viewport"  content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link rel="stylesheet" href="lib/ionic/css/ionic.css">
    <link rel="stylesheet" href="css/style.css">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/angular-translate/angular-translate.min.js"></script>
    <script src="lib/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <!--<script src=""-->
    <script src="cordova.js"></script>


    <!-- your app's js -->
    <script src="js/app.js"></script>
    <!--SERVICES-->
    <script src="js/services/services.js"></script>
    <script src="js/services/s_configDB.js"></script>
    <script src="js/services/s_clinicDB.js"></script>
    <!-- CONTROLLERS -->
    <script src="js/controllers/controllers.js"></script>
    <script src="js/controllers/c_splash.js"></script>
    <script src="js/controllers/c_communications.js"></script>
    <!--<script src="js/controllers/c_communicationsB.js"></script> 
    <script src="js/controllers/c_clock.js"></script>
    <script src="js/controllers/c_menu.js"></script>
    <script src="js/controllers/c_language.js"></script>
    <!--DIRECTIVES-->
    <script src="js/directives/directives.js"></script>
    <script src="js/directives/d_menu.js"></script>

</head>

<body ng-controller="AppComms">
    <ion-nav-view ></ion-nav-view>
</body>
</html>

At my app.js:

var SDv4 = angular.module('my_app', [
    'ionic',
    'my_app.services',
    'my_app.controllers',
    'my_app.directives'
]);

在controllers.js

var app = angular.module('my_app.controllers',[
    //'ionic',
    'my_app.c_splash',
    'my_app.c_clock',
    'my_app.c_language',
    'my_app.c_comms',
    //'my_app.c_commsb',
    'pascalprecht.translate',
    'my_app.c_menu'
]);

例如c_communications.js

var comms = angular.module('my_app.c_comms',[])

comms.controller('AppComms',['$scope',function($scope){

    …

}])

这段代码可以正常工作,但是如果我添加另一个控制器(c_communicationsB.js):

var commsb = angular.module('my_app.c_commsb',[])

并将my_app.commsb添加到controllers.js

它给了我错误:

ionic.bundle.js:8895 Uncaught Error: [$injector:modulerr] Failed to instantiate module MY_APP due to:
Error: [$injector:modulerr] Failed to instantiate module my_app.controllers due to:
Error: [$injector:modulerr] Failed to instantiate module my_app.c_commsb due to:
Error: [$injector:nomod] Module ‘my_app.c_commsb' 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://errors.angularjs.org/1.4.3/$injector/nomod?p0=MY_APP.c_commsb
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:8895:12
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:10785:17
    at ensure (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:10709:38)
    at module (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:10783:14)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13189:22
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13190:40
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=MY_APP.c_commsb&…3A63342%2FSD4v040t2%2Fwww%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13173%3A5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:8895:12
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13212:15
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13190:40
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13190:40
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=MY_APP.controlle…3A63342%2FSD4v040t2%2Fwww%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13173%3A5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:8895:12
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13212:15
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
    at http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13190:40
    at forEach (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at loadModules (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13173:5)
    at createInjector (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:13099:11)
    at doBootstrap (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:10457:20)
    at bootstrap (http://localhost:63342/SD4v040t2/www/lib/ionic/js/ionic.bundle.js:10478:12)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=MY_APP&p1=Error%…A63342%2FSD4v040t2%2Fwww%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A10478%3A12)

这是怎么回事?

您已注释掉<!--<script src="js/controllers/c_communicationsB.js"></script>

在您的代码示例中,但是已经说过该方法在这里。

您的应用似乎没有被调用。 尝试将您的应用包装为IFFY。

(function () {
    var comms = angular.module('my_app.c_comms',[]);

    comms.controller('AppComms',['$scope',function($scope){
        //controller magic here
    }])

}());

这是一个自调用函数,因此您的应用将被自己调用。

//在controllers.js

angular.module('my_app',[
    //'ionic',
    'my_app.c_splash',
    'my_app.c_clock',
    'my_app.c_language',
    'my_app.c_comms',
    //'my_app.c_commsb',
    'pascalprecht.translate',
    'my_app.c_menu'
]);

解决了,

一周前,我使用脚本来防止从浏览器的缓存中加载页面,以便在进行chrome调试时无需刷新网站,并强制始终从源中读取内容。

我不知道是谁或为什么阻止在我添加的新html页面中加载新的控制器或新的CSS,这就是让我考虑这个脚本的原因。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM