I need to load some data from server before all controllers init. Now I use the resolve of $routeProvider. But this way I need to include my resolve function returning promise into every resolve for every route. This looks not DRY-way. Any thoughts?
--
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-US.
Use the .run() block of a module.Send a jsfiddle or plunk if you need help wit the code.Cheers,
Pawel
On Monday, December 24, 2012, Sergey Chico wrote:
I need to load some data from server before all controllers init. Now I use the resolve of $routeProvider. But this way I need to include my resolve function returning promise into every resolve for every route. This looks not DRY-way. Any thoughts? --
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
What is your use case for this?
I had similar problem, I mean, back then I though I had, with my authorization system.
I had to fetch data from server to be able to figure out what is the user allowed to see, like what options in menu and what actions were possible to they.
The solution was to back everything with promises. Promises are very nice, they let you do things at once and there is no need to wait for a service to return data before the consumers of the service run.
So, the service triggers the http request and immediately return promise. If your controllers need the response, they ask the promise to resolve with callback. There is no need for the controllers to actually be postponed. They will initialize, use the promise returned by the service and once the data are available - they continue.
If the data is available before controller was initialized, the promise will trigger callback immediately. If not, the callbacks will wait. It worked for me.
Regards,
Witold Szczerba
---
Sent from my mobile phone.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
So your case is the same as my. Promises work for me very well in this scenario. Directives work very well with them as well.
Rember that you cam make entire app invisible or hidden behind some fancy "please wait" banner until every crucial data arrives (look at the API, you can resolve multiple promises in one go), so there is no need to worry how does your directives looks like when data is not yet available.
Regards,
Witold Szczerba
---
Sent from my mobile phone.
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.
This has the effect of preventing all rendering while you get things done regardless of the entry point each use has into the app. Goes grat with some css/spinner-type fode that says "please wait while loading" or whatever.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/F5yoJevAHNg/unsubscribe.
To unsubscribe from this group and all its topics, 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.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/F5yoJevAHNg/unsubscribe.
To unsubscribe from this group and all its topics, 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.
--
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/d/optout.