Wrapping multiple services in services.js module

2,028 views
Skip to first unread message

jason

unread,
May 23, 2012, 4:41:18 PM5/23/12
to AngularJS
Hi

Just wondering how to code more than 1 service into services.js. I.e.
after

angular.module(' ',[ ]).

I've completed the tutorial, read through the literature and searched
available projects. But the examples seen have only 1 service.

I have something working in which I've defined 2 modules, 1 for each
service, but this seems a bit laborious, since I had to declare each
in app.js.

A real beginner with this.

thanks for any help,

Jason

Andy Joslin

unread,
May 23, 2012, 5:50:43 PM5/23/12
to ang...@googlegroups.com
Hey Jason, 

Luckily it's super easy :-)

var servicesModule = angular.module('myApp.services', [])
servicesModule.service('Service1', function(){});
servicesModule.service('Service2', function(){});

drjason...@gmail.com

unread,
May 24, 2012, 5:04:37 AM5/24/12
to ang...@googlegroups.com
Many thanks.  I think my problem is learning Javascript as I go along as much as learning angularjs ;-)

Jason Berk

unread,
Sep 20, 2012, 9:26:32 AM9/20/12
to ang...@googlegroups.com
"I think my problem is learning Javascript as I go along as much as learning angularjs ;-)"

DITTO - I had the exact same issue.  I really think the angular group should post an 'advanced' example that deals with more real world issues....like having multiple services...and (better) explains why defining a module is worthwhile.

(a different) Jason
Reply all
Reply to author
Forward
0 new messages