0

当我部署它并在浏览器中运行它时,我的应用程序运行良好

我可以成功访问我所有的控制器/服务。它们通过子模块链接在一起。

我使用子模块来更好地为 ui-router 组织状态/路由。(以前我们在 app dot js 文件中有我们所有的状态。大约有 50 个。现在它们被组织成更小的模块)。

app.js [模块文件]

var phpApp = angular.module("phpApp",
[
    "ui-router"
    "phpApp.components" , ...

]).config(...).run(...);

components.js [模块文件,包含状态/路由]

var ComponentModule = angular.module("phpApp.components",
[
    "ui-router"
    "phpApp.components.user" , 
    "phpApp.components.client"
     ...

]).config(...).run(...);

user.js [模块文件,包含状态/路由]

var UserModule = angular.module("phpApp.components.user",
[
    "ui-router"

]).config(...).run(...);

user-controller.js // 加载正常;是一个控制器。

angular.module('phpApp.components').controller('UserController', ....);

client-controller.js // 不加载!找不到“phpApp.components”模块...

angular.module('phpApp.components').controller('ClientController', ...);

我的 index.html 文件按以下顺序加载脚本:

<script src="app.js"></script>
<script src="components/components-module.js"></script>
<script src="components/user/user-module.js"></script>
<script src="components/client/client-module.js"></script>
...
<script src="components/user/user-controller.js"></script>
<script src="components/client/**client-controller.js**"></script>

我不明白。我的客户端控制器在我的用户控制器之后加载......但它无法找到正确的模块?

我得到错误:

Uncaught Error: [$injector:nomod] Module 'phpApp.components' 
is not available! You either misspelled the module name or 
forgot to load it.

在这一点上,我感到非常困惑和沮丧。我不确定我哪里出错了。

4

1 回答 1

0

答案在于 karma 配置文件(默认为 karma.conf.js)

正如预期的那样,答案很简单。

我有一个包含所有 JavaScript 文件的规则:

"app/app.js",
"app/components/**/*.js",

您需要确保重写加载规则以首先加载所有模块 JS 文件:

"app/app.js",
"app/components/**/*-module.js", <-- modules must load first
"app/components/**/*.js",

为了帮助阐述,我将我的项目设置在:

1) controllers are in their respective xxx-controller.js files, 
2) ervices are in xxx-service.js files and 
3) modules are in xxx-module.js files
于 2016-06-07T19:51:33.857 回答