1) The login page redirects to the home page after a successful login.
if (data.status == CONSTANTS.RETURN_SUCCESS) {
$location.path("/home");
$route.reload();
}
2) I have implemented a promise to fetch data from the database before loading the home page controller in my app.js code:
.when('/home',
{
templateUrl: '/views/home.html',
resolve: {
'myAssetsData': function (myAssetsDataPromise) {
return myAssetsDataPromise.promise;
}
}
})
The promise calls a function "setAssetData()" to retrieve and set service level variables.
.service('myAssetsDataPromise', ['myassets_service', '$log', function (myassets_service, $log) {
$log.debug("Initialize myAssetsDataPromise");
var return_data = {}
//fetch and set some service level variables
var promise = myassets_service.setAssetData()
return {
promise: promise,
getAssets: function () {
return return_data.status = "success";
}
};
}
3) The home page contains a logout link that clears the session on the server side and redirects back to the login page.
$location.path("/");
4) Everything functions correctly on the initial visit. However, upon logging out and then logging back in or revisiting the home page, the promise does not execute again unless the page is reloaded or history/cache is cleared. Even using $route.reload() does not solve the issue.
Although it's understood that once a promise is resolved, it won't reload, the goal is to trigger the promise again when returning to the page.