I have been working on a "non trivial" angular JS application and I am somewhat disappointed on myself and this framework for not finding truly viable solutions, to the following problems.
- AngularJS should have a mechanism that, before run-time, should be able to do HTTP requests in order to get data and set it to providers. This would be extremely useful in getting route permissions, user data, things you need before actually bootstrapping the app.
Right now, I seen articles describing how to load jQuery before angular, manually bootstrapping angular just after some jQuery's ajax calls -> and inject the received data into Angular.
- There should be a middle-ware that can be used in order to verify roots. A hook where, before any root is displayed you can do a check, for example to see if the user is authenticated, a token is stored in session storage, etc.
Right now, I've seen attempts with using the ui-router and the $rootScope.$on('$stateChangeStart')
event.
This "somewhat" works, but it's not elegant, not out of the box and if you don't fiddle with the settings, it triggers infinite loops.
Also, the ui-router uses resolves, which are great in getting resources before the view compiles. BUT, gues what, you can't get the "$state" from the resolve function. So, yo can't redirect to another view, if the data you requested isn't the on you wanted.
Angular makes it very complicated to load controllers and views for a state, depending on some data - ergo. user roles. It's not really the way to go, but in some cases, it would be useful to decide which controller to load for which route, directly from the router and not using templates in the view.
The reason behind this post, is to see how you guys tackle with these problems.
I hope you prove me wrong and there are much better ways to do the above, and with code examples, I'd be very interested to know about them.