Still trying to wrap my head around the beast that is AngularJS and would like the opinions of Stack Overflow. If I am designing an application with angular that is going to have SPA functionality, I would like to have some area where I can have "global" functions such something like a $scope.showMenu variable which can be bound with ng-class to a side bar menu so that when it is clicked it will slide out.
Having a collection of variables and functions that are available to all of the subsequent views in the application, where would these go?
My idea from reading about modules would be that I should make a parent module which has its own controller that contains all of my global level functions and variables and custom directives.
Then on "inner" content (when navigating around) each page should have its own module, complete with controllers, services and directives?
Thus my application might look something like the following
HTML
<body ng-app="global" ng-controller="globalController">
{{globalTest}}
<div ng-controller="pageOneController">
{{pageOneTest}}
</div>
</body>
JS
<script>
angular.module('global',['pageOne']);
angular.module('global').controller('globalController', globalController);
globalController.$inject = ['$scope'];
function globalController($scope) {
$scope.globalTest = "global test";
}
angular.module('pageOne',[]);
angular.module('pageOne').controller('pageOneController', pageOneController);
pageOneController.$inject = ['$scope'];
function pageOneController($scope) {
$scope.pageOneTest = "page one test";
}
Plunker - http://plnkr.co/edit/wxja7smqOJiSbUi7mfu4?p=preview
Is this the proper "angular way" of going about making a large scale web application? Or is it better to just have a single "module" and have multiple controllers?