为什么可以't Angular找到我的控制器了吗

Why can't Angular find my controller?

本文关键字:我的 控制器 Angular 为什么      更新时间:2023-09-26

我在尝试加载任何视图时都会收到"Error: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>

我在这里做错了什么?

您包括:

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

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

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

您缺少controllers目录

<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>