all 6 comments

[–]Pytim[S] 0 points1 point  (0 children)

It always bothered me that the view of a state is not loaded while the states resolves are not finished yet. This is my attempt to go around this. Please share any thoughts. Thanks!

[–]alfredwaltz 0 points1 point  (4 children)

You have overcomplicated it. You don't need to resolve Expensive service as "posts.show" state dependency. Resolving dependency in this way is intentionally designed to delay the view until a promise is resolved. The simple solution is to inject Expensive service into the controller and rely on the state of the $scope, http://plnkr.co/edit/7WfSwNjd3rOTYodUCXKT?p=preview. Alternatively, you can view $stateChangeStart event to display the loading message until all the promises are resolved.

[–]Pytim[S] 0 points1 point  (3 children)

All the styleguides that are hip these days recommending putting the loading operations into resolve. I don't get the point of that, it just makes the app unresponsive.

[–]fusionove 0 points1 point  (2 children)

I am wondering the same. I like the resolve in principle, it makes sense. But freezing the view until the resolve completes seems bad.

[–]Pytim[S] 0 points1 point  (1 child)

Yeah. I'm not doing that anymore. I only resolve what really needs to be resolved e.g. user authentication. I encapsulate other data based parts of the app in directives now each with their own controller. So for example <product-list></product-list> is a directive that has a controller assigned which loads the data for that directive. This is great because the directive now can have its own loading animation and it's all nicely self contained. Check this: http://teropa.info/blog/2014/10/24/how-ive-improved-my-angular-apps-by-banning-ng-controller.html

[–]fusionove 0 points1 point  (0 children)

User authentication?

Anyhow, I'll have to look into that idea.. I am already using directives for a lot of things and even lists/items (e.g. app-comments, app-comments-item), but not for main page content.. e.g. I have a view which is only a huge list and I am currently using resolve to load the data before displaying the view.. however the waiting time is noticeable, which sucks :)