I am intrigued by the behavior of AngularJS. I am wondering if AngularJS modules inherit dependencies from other modules. Let's consider the following structure:
var PVNServices = angular.module('PVN.services', []);
PVNServices.factory('ItemService', ['$q', 'apiUrl', '$http', 'errorHandler', function($q, apiUrl, $http, errorHandler) {
return {
getAlert: function(alert_id, user_id, category_id) {
return $http({ method: 'get',
url: apiUrl + 'getAlert/',
params : {
'alert_id' : alert_id,
'user_id' : user_id,
'category_id' : category_id,
}
}).then(function(res){return res.result }, errorHandler);
}
}
}]);
var PVNControllers = angular.module('PVN.controllers', ['PVN.services']);
PVNControllers.controller('AppController', ['$scope', 'ItemService', function($scope, ItemService) {
$scope.getAlert = function(alert_id, user_id, category_id) {
ItemService.getAlert(alert_id, user_id, category_id).then(function(alert){
$scope.alert = alert;
}
}
}]);
var PVNDashboard = angular.module('PVN', ['ngSanitize','ngMaterial','PVN.controllers'], function($interpolateProvider) {
$interpolateProvider.startSymbol('<<');
$interpolateProvider.endSymbol('>>');
});
PVNDashboard.run(function() {
moment.locale('nl');
});
<body class="" ng-app="PVN">
</body>
In this setup, can I utilize the ItemService in the PVNDashboard module because it has controllers as a dependency, which in turn depends on services? Also, due to the ng-app being set to the PVN module, will the configuration of the PVN module (such as setting moment.js locale in this case) persist in the services because it is the first to run?