为什么Angular找不到我的控制器?

时间:2015-07-06 13:29:28

标签: javascript angularjs module controller

我得到"错误:ng:areq"尝试加载任何视图时出错。我有以下文件结构:

-app/modules
    -- dashboard
       --- views/ dashboard.html
       --- controllers/ dashboard-ctrl.js
-app.js

我有一个模块可以容纳我的所有控制器,名为" si.modules"。我已将其添加为主app.js模块中的依赖项,如下所示:

var app = angular.module('xenon-app', [
    'ngCookies',
    'ngAnimate',
    'ui.router',
    'ui.bootstrap',

    'oc.lazyLoad',

    'xenon.controllers',
    'xenon.directives',
    'xenon.factory',
    'xenon.factory.si',
    'xenon.services',
    'uiSwitch',
    'angularUtils.directives.dirPagination',
     'si.modules',

    // Added in v1.3
    'FBAngular',

    //Added for image uploader 
    'angularFileUpload',

    //ngtags input
    'ngTagsInput',

]);

我还在我的index.html中包含了控制器文件,如下所示:

  <script src="app/scripts/app.js"></script>
  <script src="app/modules/Dashboard/dashboard-ctrl.js"></script>

我在这里做错了什么?

2 个答案:

答案 0 :(得分:0)

您包括:

<script src="app/modules/Dashboard/dashboard-ctrl.js"></script>

但是从你的项目结构来看应该是:

<script src="app/modules/dashboard/controllers/dashboard-ctrl.js"></script>

您缺少controllers目录

答案 1 :(得分:0)

<script src="app/scripts/app.js"></script>
<script src="app/modules/Dashboard/dashboard-ctrl.js"></script>

假设是,

<script src="app.js"></script>
<script src="app/modules/dashboard/controllers/dashboard-ctrl.js"></script>
相关问题