creating service objects which wrap resources in Angular 1.0 RC4

959 views
Skip to first unread message

xrd

unread,
Apr 9, 2012, 8:37:01 PM4/9/12
to ang...@googlegroups.com
I'm struggling to understand how to create services with the new 1.0 angular modules.

I put a JS Fiddle here:


My goal is to create a service called "Foo" which I can use in other controllers (like the FooCtrl) which wraps a resource.

I show in the fiddle what I used to do (use angular.service(...)) but this no longer is the way, right?

Any suggestions?  What am I missing?

Also, with this new interface, do I still need to do FooCtrl.$inject = [ 'Foo' ]; (as long as I am minimizing...) or does this now handle this type of circumstance automatically since it is more explicit?

Chris

Dalci Bagolin

unread,
Apr 9, 2012, 8:46:30 PM4/9/12
to ang...@googlegroups.com
You need to put "return" before $resource function 


Dalci Bagolin


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/0szip-1h8IsJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

xrd

unread,
Apr 9, 2012, 9:24:48 PM4/9/12
to ang...@googlegroups.com
Thanks Dalci,

That worked!  

When I try to separate the service into it's own file like this:
  • service.js file with the factory for "Foo" 
  • and a foo.js with "FooCtrl"
I get "Unknown provider:  FooProvider <- Foo"

I don't know how to simulate this in jsfiddle.  Any ideas on what this means or what I am missing?  Should I have the same angular.module( "foo", ['ngResource']) inside of both files?  

Chris
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Dalci Bagolin

unread,
Apr 9, 2012, 9:51:44 PM4/9/12
to ang...@googlegroups.com
I think you need to create a module to Services.

Take a look in this application:


Dalci Bagolin
-------------------------------------------



To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/OGRFB6upxt4J.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages