Sceneraio
I want to load my AngularJS controllers automatically without having to manually include them in the main html file so that when I reference them in my route config file they will successfully register.
How do I auto load the controllers in the simplest way possible without adding too much complexity?
Directory Structure / Code
Bottom Contents of index.html (index.php to be exact)
...
<script src="app/app.js"></script>
<script src="app/route-config.js"></script>
</body>
</html>
app.js
angular.module('Main', ['ui.router', 'datatables', 'ngResource'])
.controller('MainController', function(){
});
angular.module('Action', ['Main']);
route-config.js
angular.module('Main').config(config);
function config($stateProvider, $urlRouterProvider)
{
$urlRouterProvider
.when('action', 'action')
.when('issue', 'issue')
.when('lesson', 'lesson')
.when('opportunity', 'opporutnity')
.when('risk', 'risk')
.otherwise('main');
$stateProvider
.state('main', {
url: "/main",
//templateUrl: '/app/tool/home/home.html',
controller: 'MainController'
});
$stateProvider
.state('action', {
url: "/actionitems",
templateUrl: '/app/tool/action/ActionItems.html',
controller: 'ActionController'
})
$stateProvider
.state('action.summary', {
url: "/actionitems/all",
templateUrl: '/app/tool/action/ActionItems.html',
controller: 'ActionController'
})
}
ActionController.js
angular.module('Action')
.controller('ActionController', ActionController);
function ActionController($resource)
{
$resource('actionitems.json').query().$promise.then(function(actionitems){
this.all = actionitems;
});
}

