Did some research before posting this, but couldn't find a solution yet.
I want to create separate controller files for each views, and load them on-demand (sort of). Is it possible? Like referencing controllers from respective view files?
app.js - main entry point
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider.when('/', {
templateUrl: 'views/login.html',
controller: 'loginController'
});
index.html
<html>
<head>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<div ng-view>
</div>
</body>
views/login.html
<div>
<h1>{{greeting}}</h1>
</div>
<script src="js/controllers/loginController.js"></script>
loginController.js
myApp.controller('loginController',function($scope){
$scope.greeting = "Hello World!";
});
This may be some dumb idea (I definitely don't like refencing JS files in the head section). Any ideas?