Async/promises during module config

2,631 views
Skip to first unread message

Mauro Servienti

unread,
Jul 31, 2013, 1:20:17 PM7/31/13
to ang...@googlegroups.com

Hi,

 

at application startup time I need to get some configuration data from the server, e.g. via $http, in order to successfully setup the client side routing, I have to problems:

 

a)      How to inject $http in the app config handler? it seems to accept only providers, so an $httpProvider, but then a need the concrete service;

b)      After issuing the http request I need to wait for the promise to resolve before moving on with the configuration: how to?

 

Cheers,

.m

 

Mauro Servienti

unread,
Jul 31, 2013, 1:45:45 PM7/31/13
to ang...@googlegroups.com
As far as I have understood it is not possible at all, period.
The only option I am left with is to generate a module sever side with the configuration info I need before loading the entire application.

Any other suggestion?
.m

Sent from my Yellow Lumia 920

From: Mauro Servienti
Sent: ‎31/‎07/‎2013 19.20
To: ang...@googlegroups.com
Subject: [AngularJS] Async/promises during module config

--
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

satish venkatakrishnan

unread,
Jul 31, 2013, 10:29:40 PM7/31/13
to ang...@googlegroups.com
Have you tried route resolve 

Grant Rettke

unread,
Jul 31, 2013, 11:58:35 PM7/31/13
to ang...@googlegroups.com
On Wed, Jul 31, 2013 at 12:45 PM, Mauro Servienti <ma...@topics.it> wrote:
> Any other suggestion?

We did the same thing, it wasn't worth pursuing further.

mlegenhausen

unread,
Aug 1, 2013, 9:43:57 AM8/1/13
to ang...@googlegroups.com
I don't think this feature will ever come, cause the config phase is not intended for that or rather you should not load your configuration via a second http call.

There are 3 possiblities:

1. Generate constant module during build time. For example via grunt using: https://github.com/werk85/grunt-ng-constant
 - Use this when your configuration only changed at build time
2. Add a module to your index.html with is generated on the server.
 - Use this when your configuration changes only need to take place when the client reloads the page

<html>
<head>
<script src="angular.js"></script>
<script>
angular.module('config').constant(
<%= // JSON.stringify your config here and %>
);
</script>
<script src="app.js"></script>
</head>

3. When you configuration is changing rapidly and should take effect during the running application you need to make your application aware of this dynamic behaviour so the config phase is no good place for this and you should use resolve or when you need it for routing should implement your own router that can handle this.

Mauro Servienti

unread,
Aug 2, 2013, 2:12:01 PM8/2/13
to ang...@googlegroups.com

Thanks, in the end I opted for the second option.

 

.m

Reply all
Reply to author
Forward
0 new messages