question about MIT licensed angular $resource

221 views
Skip to first unread message

Dobrica Pavlinusic

unread,
Oct 31, 2010, 1:35:30 PM10/31/10
to Angular
First, let me say that I'm amazed how logical angular is. I watched
video first, and then went started reading wiki and went through
tutorial at getangular.com. I was hooked. I had several use cases for
our internal needs, so I started writing REST server for our data that
is available at:

http://github.com/dpavlin/angular-mojolicious

(it's perl code based on mojolicious framework and provides in-memory
REST API, but that's not important).

Then I tried examples which worked on getangular.com against
angularjs.org checkout on github, and I was at first surprised that
things like ng-entity didn't exists in checkout. Hack, not a problem,
it seemed, there is $resource which will help.

But, after few days, this is the point in which I'm stuck. I can't
find $resouce example which works and uses code with backward
incompatible changes (changing {inject:['$resource']} to {$inject:
['$resource']}) didn't help).

I have working $xhr stub, so I could generate controllers around that,
but $resource seems like a solution for just that problem, so I'm
first asking here.

Everything I saw so far is sufficiently advanced to call it magic :-)

Misko Hevery

unread,
Oct 31, 2010, 3:23:21 PM10/31/10
to ang...@googlegroups.com
Hi Dobrica,

We are happy to help out. Do you think you could send us a code sample so that we have something more concrete talk about, and what exactly you have trouble with?

I have attached an simple example of how to fetch data using $resource.  Because it has XHR, you need to run it through a web server so that url read http://. file:// urls, will cause issues in some browser (like chrome) since they consider it a violation of XHR. (but file:// should work on safari)

Look at tho attached code, and let me know which part does not make sense, and you need more help with. Also I assume that you have read http://angularjs.org/Service:$resource

-- Misko




--
You received this message because you are subscribed to the Google Groups "Angular" group.
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.


example.zip

Dobrica Pavlinusic

unread,
Oct 31, 2010, 5:31:09 PM10/31/10
to Angular
Thanks for $resource example. I tried to get buzz example working, and
it seems
that I don't have a problem with $resource, but with angular.service()
and new
$inject.

I have similar problem with http://angularjs.org/Cookbook:DeepLinking

It seems that something like:

angular.service('myApplication', function($route){
$route.when("", {template:'/cb/welcome.html',
controller:WelcomeCntl}); // never called
...
}, {$inject:['$route']});

isn't sufficient. I don't see $route.when initialization when I dump
{{$route}} i just get:

{"current":null,"routes":{}}


On Oct 31, 8:23 pm, Misko Hevery <mi...@hevery.com> wrote:
> Hi Dobrica,
>
> We are happy to help out. Do you think you could send us a code sample so
> that we have something more concrete talk about, and what exactly you have
> trouble with?
>
> I have attached an simple example of how to fetch data using $resource.
>  Because it has XHR, you need to run it through a web server so that url
> read http://. file:// urls, will cause issues in some browser (like chrome)
> since they consider it a violation of XHR. (but file:// should work on
> safari)
>
> Look at tho attached code, and let me know which part does not make sense,
> and you need more help with. Also I assume that you have readhttp://angularjs.org/Service:$resource
>
> -- Misko
> > angular+u...@googlegroups.com<angular%2Bunsu...@googlegroups.com >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/angular?hl=en.
>
>
>
>  example.zip
> 2KViewDownload

Misko Hevery

unread,
Oct 31, 2010, 6:19:59 PM10/31/10
to ang...@googlegroups.com
That is because we changed the rules about when things are run

angular.service('myApplication', function($route){
 $route.when("", {template:'/cb/welcome.html',
controller:WelcomeCntl}); // never called
 ...
}, {$inject:['$route'], $creation:'eager'});

and it should do the trick.

-- Misko

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

Derek Prothro

unread,
Oct 31, 2010, 6:11:18 PM10/31/10
to ang...@googlegroups.com
Try changing the third parameter to angular.service to {$inject:['$route'], $creation: 'eager-published'}. I ran into this same problem a few days ago when updating to 0.9.0 and this fixed it for me. I think there's other values you can pass in for $creation, but I'm not sure what they are or what they do.

On Sun, Oct 31, 2010 at 2:31 PM, Dobrica Pavlinusic <dpa...@gmail.com> wrote:
To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Alex Eagle

unread,
Nov 20, 2010, 7:47:16 PM11/20/10
to Angular
Can someone on the project please update the docs? None of them
(deeplink cookbook nor $route reference) mention the $creation
property. Also, the old docs on http://angularjs.org are missing the
'$' on $inject.

-Alex

On Oct 31, 2:11 pm, Derek Prothro <dprot...@google.com> wrote:
> Try changing the third parameter to angular.service to {$inject:['$route'],
> $creation: 'eager-published'}. I ran into this same problem a few days ago
> when updating to 0.9.0 and this fixed it for me. I think there's other
> values you can pass in for $creation, but I'm not sure what they are or what
> they do.
>
> On Sun, Oct 31, 2010 at 2:31 PM, Dobrica Pavlinusic <dpav...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Thanks for $resource example. I tried to get buzz example working, and
> > it seems
> > that I don't have a problem with $resource, but with angular.service()
> > and new
> > $inject.
>
> > I have similar problem withhttp://angularjs.org/Cookbook:DeepLinking
> > <angular%2Bunsu...@googlegroups.com<angular%252Bunsubscribe@googlegroup s.com>>

Misko Hevery

unread,
Nov 20, 2010, 8:18:40 PM11/20/10
to ang...@googlegroups.com
sorry alex, we are currently in the process of rewriting the documentation. You can see the new one here: http://code.angularjs.org/docs-0.9.4/

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