You can't really do precisely what you're asking -- prevent injection, but within the code that instigates the "getting of configuration information" (which *should* return a promise), you can ensure that the promise is resolved before you allow your app to proceed.
In other words, as the user logs in you can instigate the retrieval of the information and you can wait until that promise is resolved before proceeding away from the login process and on to whatever the user should see after logging in. There are other options but that's one fairly rudimentary one. On Wednesday, May 28, 2014 4:37:41 AM UTC-7, Paulo Silva wrote: > > 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.
