Is there a way to postpone the initialization of my Application Controller (similar to using the 'resolve' attribute in the router) when reloading a page? Or more importantly, how can I delay the rendering of the view until my controller has successfully retrieved the user object upon page reload?
Currently, I have this code snippet at the beginning of my ApplicationCtrl:
if (localStorage.getItem('token') && localStorage.getItem('token') != 'null')
{
sessionStorage.setItem('token', localStorage.getItem('token'))
}
if (sessionStorage.getItem('token') && sessionStorage.getItem('token') != 'null')
{
UserSvc.getUser()
.then(function (response)
{
loadUser(response.data)
})
.then(function (error)
{
if (error) $scope.logout()
})
}
This piece of code verifies the authentication token and then fetches the user object from the database based on that token.
The issue here is that the user data appears with a slight delay after the page loads. This results in an empty navigation bar initially, which is then populated with the user's display name a few milliseconds later.
Is there a way to defer displaying the view until the initial user request has been successfully completed?