Hi guys, just trying to figure out how can I have services in separate files. My current file hierarchy is this one:
<https://lh3.googleusercontent.com/-D0NCN1u8hP0/VXtS2kxVZvI/AAAAAAAACUQ/jz94Qitnlig/s1600/aaaa.PNG> Just following the example in the new angular router page. When I try to add a service like this one: angular .module('home') .service('HomeService', [HomeService]); function HomeService() { var homeService = {}; homeService.test = function() { return 'test'; }; } and inject it in the controller like this: angular .module('home') .controller('HomeController', [ 'HomeService', HomeController ]); function HomeController(HomeService) { this.name = 'Friend'; this.test = HomeService.test(); } I just get an error in the console: router.es5.js:384 Could not instantiate controller HomeController If I put the service in the same file as the controller, everything works. angular .module('home') .service('HomeService', [HomeService]) .controller('HomeController', [ 'HomeService', HomeController ]); function HomeService() { var homeService = {}; homeService.test = function() { return 'test'; }; return homeService; } function HomeController(HomeService) { this.name = 'Friend'; this.test = HomeService.test(); } Do you know how can I create the service in a separate file and inject it to different controllers?? -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
