Hi,

First, let me explain what is my application and what I want to achieve.
My application requires the user to login so that he can access all my 
server requests. For that, I'm using http-auth-interceptor that detects a 
401 error and popups the login page. When the user does the login I expect 
to load some initial general Configuration / UserConfigurations data that 
is required by all my controllers/services/etc.

In practice what this means is that I have a ConfigurationService that I 
inject in all my controllers. My ConfigurationService needs to load the 
configuration from my REST backend.
I want to make sure that injection is only done when the $http finishes. 
1) So, how can I achieve this?


My "hacky" attempt is to use a synchronous ajax request on my 
ConfigurationService constructor. That works OK but feels "hacky" and still 
have 1 problem: when my $http request fails the ConfigurationService is 
still injected and all my controllers load up with lot's of undefined/null 
problems (as my configurations weren't loaded properly). 
2) I have no idea how to fix this....


I understand that maybe the best way to achieve this is using Promises but 
this is a ConfigurationService that is used very often in my application. I 
feel it would complicate my code because I'll have to use promises in 
basically all my application... In this specific case of "data" that is 
required almost for bootstrapping my application I feel it's better to 
guarantee a synchronous behaviour. 

Tips, guidance, best practices are most welcomed, 

TIA
 -- pjfsilva

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to