Angular 控制器未定义?

Angular Controller is not defined?

错误:[ng:areq] http://errors.angularjs.org/1.3.15/ng/areq?p0=homeController&p1=not%20aNaNunction%2C%20got%20undefined

我收到上述错误

Controller.js

angular.module('app').controller('homeController', function($scope) {});

app.js

 var app = angular.module('app', ['base', 'ngRoute', 'routeResolverServices']);
angular.bootstrap(document, ['app']);
return app;

由于您脚本的顺序,这不起作用(并且不会按照您定义的方式以任何顺序工作)。当 Controller.js 首先加载时,仍然没有名为 "app" 的模块。当 app.js 首先加载时,它会立即在没有控制器的情况下引导应用程序。

最好每个文件定义一个模块,例如:

feature1.js

angular.module("feature1", []).controller("homeController", function(){});

app.js

var app = angular.module('app', 
             ['base', 'feature1', 'ngRoute', 'routeResolverServices']);
app.bootstrap(document, ['app']);

最后加载 app.js:

<script src="feature1.js"></script>
<scirpt src="app.js"></script>