I have 3 modules in my AngularJS application, for example. main , home and product . main with home and product modules as dependencies ( ng.module('main', ['home', 'product']) ), while home and product modules have no dependencies ( ng.module('product', []) ng.module('phome', []) ), can the product module access the module's home service? WHY???
Below is a sample code of my application that has the same script and the same problem. And this is the JSfiddle link .
<!DOCTYPE html> <html ng-app="main"> <body ng-controller="MainController as mainController"> {{mainController.name}} <script type="application/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script> (function (ng) { var homeModule = ng.module('home', []); homeModule.service("HomeService", [function () { var homeService = this; homeService.getName = function () { return "Home Service"; } }]); var productModule = ng.module('product', []); productModule.service("ProductService", ["HomeService", function (HomeService) { var productService = this; productService.getName = function () { return "Product Service - " + HomeService.getName(); }; }]); var mainModule = ng.module('main', ['home', 'product']); mainModule.controller("MainController", ['ProductService', function (ProductService) { var mainController = this; mainController.name = ProductService.getName(); }]); })(angular); </script> </body> </html>
source share