1

我使用angular-seed启动了一个 angular 项目,并且使用 index-async.html 它默认使用 angular-loader 和script.js。我在这个项目中添加了两个控制器,每个控制器都在两个单独的文件中。第一个控制器的文件如下所示:

angular.module('myApp.controllers').controller('FirstCtrl', ...

第二个控制器的文件如下所示:

angular.module('myApp.controllers').controller('SecondCtrl', ...

然后在 app.js 主文件中:

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

所有三个文件都添加到 script.js 中:

$script([
      'bower_components/angular/angular.js',
      'bower_components/angular-route/angular-route.js',

      'js/app.js',

      'js/controllers/first-ctrl.js',
      'js/controllers/second-ctrl.js',
    ], function() {
      angular.bootstrap(document, ['myApp']);
    });

当我运行该应用程序时,有时它可以工作,有时我会收到错误:

未捕获的错误:[$injector : nomod] http://errors.angularjs.org/1.2.20/$injector/nomod?p0=myApp.controllers

错误:[ng:areq] 参数“FirstCtrl”不是函数,未定义

笔记。为简洁起见,我省略了 routeprovider,但我先使用 FirstCtrl 去路由。如果我改为使用 SecondCtrl 进行路由,我会遇到类似的问题。

我认为我对 angular-seed 的更改并没有太大,所以我想知道添加更多控制器是否正确?

4

1 回答 1

0

我发现 $script.js v2(尚未发布)已经支持并行脚本加载,但也保留了执行顺序。

您可以尝试通过复制以下文件中的内容来升级它并替换index-async.html.

https://github.com/ded/script.js/blob/v2/src/script.js

于 2014-07-22T05:59:45.157 回答