I have many controllers in app and I don't want to load them upfront as the combined JS becomes very heavy.
So I have tried following:
In my main app.js, I have route defined as below:
$routeProvider.when('/myaccount', {
templateUrl: 'my-account.html',
title: 'My Account'
})
The my-account-controller.js has controller defined like:
angular.module('myApp',[]).controller('my-account', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
And finally in my-account.html, I have a script tag which should load the controller syncronously before using it. I am attaching that contorller with ng-controller directive:
script src='/assets/my-account-controller.js'
<div class="container" ng-controller='my-account'>
...
</div>
The problem is somehow, Angular can not identify my-account as controller and it throws following error:
Error: [ng:areq] Argument 'my-account' is not a function, got undefined
Can someone tell me what is the missing piece?