Reputation: 2296
I'm using AngularJS and the Ionic Framework to build an app. My app needs to have a logout button. When the user presses the logout button, I would like to reload the page so that the app is re-bootstrapped and all cached data is wiped clean. Based on this StackOverflow Question I should be able to just do $window.location.reload(true)
. That works fine if I'm just running the app in the browser via ionic serve
. However, when I run it on an actual device, the screen just goes blank and never comes back. How can I reload/refresh the page on the mobile device without getting a blank screen?
EDIT: Here's my actual code:
angular.module('login').controller('logoutController', ['$state', '$window', function ($state, $window) {
$state.go('login');
$window.location.reload(true);
}]);
I'm trying to reload the location after transitioning to the login
state.
Upvotes: 0
Views: 2652
Reputation: 2296
The code above works fine. It turns out that my problem was with how I was transitioning to the logout
state. If I use href
on the ion-item
, then it causes the blank screen issue:
<ion-item nav-clear menu-close class="item-icon-left" href="#/logout">
Logout
</ion-item>
However, if I use ui-sref
on the ion-item
, then the blank screen does not occur:
<ion-item nav-clear menu-close class="item-icon-left" ui-sref="logout">
Logout
</ion-item>
Don't ask me how or why that happens. That's just what I have observed.
Upvotes: 1
Reputation: 71
I just tested $window.location.reload(true) within my apps' logout function and it works fine (also within the actual app).
In order to solve your problem, please get sure that
you added $window
as dependency in your view's controller
you send your user to the apps entry view, by calling
$state.go("your-entry-view")
within your logout function or
by defining a fallback state within your $stateProvider
config:
$urlRouterProvider.otherwise('/your-entry-views-url')
If that doesn't help, provide us with some more details, like the controller where you are calling the logout function and your state config. Also your console output could help.
Upvotes: 0