2015-11-23 34 views
3

我創建一個應用程序angularJS,並決定將控制器分成多個文件。這是我有:AngularJS - 添加控制器文件觸發未被捕獲的錯誤

申請宣告該模塊,我有一個文件有以下內容:

文件:controllers.js

angular.module('starter.controllers', []); 

,我使用的是其他控制器之一所謂ConnectionsController: 文件:ConnectionsController.js

angular.module('starter').controller('ConnectionsController', ['$scope', '$http', function($scope, $http){ 

}]); 

在app.js,我有以下幾點: 文件:app.j小號

var app = angular.module('starter', ['ionic', 'starter.controllers', 'ConnectionsController','starter.MoreOptionsController','starter.OrdersController', 'starter.ProfileManagementController', 'starter.UserAccessController', 'starter.services']); 

當我運行應用程序,它會觸發一個錯誤:

Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: 
Error: [$injector:modulerr] Failed to instantiate module ConnectionsController due to: 
Error: [$injector:nomod] Module 'ConnectionsController' 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. 

我在做什麼錯在聲明控制器或鏈接他們app.js文件?

感謝,

更新:內容的index.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

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

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 

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

    <!-- your app's js --> 
    <script src="js/app.js"></script> 
    <script src="js/controllers.js"></script> 
    <script src="js/ConnectionsController.js"></script> 
    <script src="js/OrdersController.js"></script> 
    <script src="js/services.js"></script> 

    </head> 
    <body ng-app="starter"> 
    <!-- 
     The nav bar that will be updated as we navigate between views. 
    --> 
    <ion-nav-bar class="bar-stable"> 
     <ion-nav-back-button> 
     </ion-nav-back-button> 
    </ion-nav-bar> 
    <!-- 
     The views will be rendered in the <ion-nav-view> directive below 
     Templates are in the /templates folder (but you could also 
     have templates inline in this html file if you'd like). 
    --> 
    <ion-nav-view></ion-nav-view> 
    </body> 
</html> 
+0

您是否在index.html中聲明瞭您的新文件? – wdoering

+0

所以錯誤很明顯:沒有模塊'ConnectionsController',這從你發佈的內容中是顯而易見的。 – dfsq

+0

@wdoering忘了這樣做,但只是通過使用>,並沒有奏效。 –

回答

2

的錯誤是不言自明:你不必模塊ConnectionsController。請注意,當你聲明的主要應用模塊像

angular.module('starter', [ 
    'ionic', 
    'starter.controllers', 
    'ConnectionsController', 
    // etc ... 
]); 

這意味着模塊starter取決於其他幾個模塊,你的情況ionicstarter.controllersConnectionsController。但是,ConnectionsController是控制器名稱,它不是一個模塊。所以你不必把它列爲模塊依賴。

+0

大......現在工作的失誤在這裏消失了,但奇蹟般地出現其他錯誤是由於出現變化是:錯誤:[NG:AREQ]參數「UserAccessController」不是一個函數,得到了不確定 –

+0

沒關係,知道了工作:)感謝您的幫助。 –

相關問題