Use custom service in config()

3,063 views
Skip to first unread message

wingy

unread,
Aug 15, 2012, 2:18:44 AM8/15/12
to ang...@googlegroups.com
In this demo I am trying to get a service I declared in the config() method.


It says it cannot be found.

Is there a way to make this work?

Wingy

Marco Alves

unread,
Aug 15, 2012, 6:05:41 AM8/15/12
to ang...@googlegroups.com
Just out of curiosity, why are you doing that?

Pawel Kozlowski

unread,
Aug 15, 2012, 6:23:12 AM8/15/12
to ang...@googlegroups.com
hi!

On Wed, Aug 15, 2012 at 8:18 AM, wingy <johnn...@yobistore.com> wrote:
> In this demo I am trying to get a service I declared in the config() method.

It won't work since during the config phase service instances are not
created yet. You've got access to providers only (which are kind of
blueprints for creating instances). What you could do is to use the
'run' phase to do something with your service instances:
http://plunker.no.de/edit/9nF9H6?live=preview

In short:
1) In the config phase you've got only access to constants and
providers. Instances are not yet created at this point.
2) In the run phase instances are already created, you can't play with
providers anymore here.

Check the "Module Loading & Dependencies" section in
http://docs.angularjs.org/guide/module

Cheers,
Pawel

> http://plunker.no.de/edit/zEVozN?live=preview
>
> It says it cannot be found.
>
> Is there a way to make this work?
>
> Wingy
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en.
>
>

Johnny Luu

unread,
Aug 15, 2012, 7:37:51 AM8/15/12
to ang...@googlegroups.com
The thing I want to do is to log each HTTP response and request.

And for that to happen I need to use MyLogger inside config() since there is where you configure the $http request and response formatters.

It seems that there is no way to do this in the config() handler.

Wingy

Johnny Luu

unread,
Aug 15, 2012, 7:38:02 AM8/15/12
to ang...@googlegroups.com
Read my other response.

Wingy

--
Reply all
Reply to author
Forward
0 new messages