force view to reload in ionic2 framework
Solution 1
Ionic 1
I haven't used Ionic 2 but currently i m using Ionic 1.2 and if they are still using ui-router than you can use reload: true in ui-sref
or you can add below code to your logout controller
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
Angular 2
Use
$window.location.reload();
or
location.reload();
Solution 2
Found this answer here, (please note especially the line this.navCtrl.setRoot(this.navCtrl.getActive().component);
which is by far the simplest solution that I've come across to reload present page for Ionic 2 & 3 and later versions of Angular (mine is 4), so credit due accordingly:
RELOAD CURRENT PAGE
import { Component } from '@angular/core';
import { NavController, ModalController} from 'ionic-angular';
@Component({
selector: 'page-example',
templateUrl: 'example.html'
})
export class ExamplePage {
public someVar: any;
constructor(public navCtrl: NavController, private modalCtrl: ModalController) {
}
refreshPage() {
this.navCtrl.setRoot(this.navCtrl.getActive().component);
}
}
If you want to RELOAD A DIFFERENT PAGE please use the following (note this.navCtrl.setRoot(HomePage);
:
import { Component } from '@angular/core';
import { NavController, ModalController} from 'ionic-angular';
import { HomePage } from'../home/home';
@Component({
selector: 'page-example',
templateUrl: 'example.html'
})
export class ExamplePage {
public someVar: any;
constructor(public navCtrl: NavController, private modalCtrl: ModalController) {
}
directToNewPage() {
this.navCtrl.setRoot(HomePage);
}
}
Related videos on Youtube
Basit
Updated on January 25, 2020Comments
-
Basit about 4 years
After going through Clear History and Reload Page on Login/Logout Using Ionic Framework
I want to know same question, but for ionic2 using typescript.
On login and logout I need reload the
app.ts
, because there are classes that run libraries on construct.it would be basically redirect to home and reload.
-
Basit about 8 yearsI have already posted link to answers of ionic1.. so this really does not help
-
Siddharth Pandey about 8 yearsOk Let me give it a try than will come back to you
-
Siddharth Pandey about 8 yearsBro are you using angular 2
-
Basit about 8 yearsYes ionic2 comes with angular2
-
Basit about 8 yearsdo you want to write that in answer, so I can accept it as answer
-
Siddharth Pandey about 8 yearsLet us continue this discussion in chat.
-
Jorge Luis Jiménez about 7 yearsThat does not work for Ionic 2, it is different in the new version.
-
Yokesh Varadhan over 6 yearsdo we need to add import for ionic2 @paulitto
-
paulitto over 6 years@YokeshVaradhan yes you'll need to import it from ionic-angular
-
user2828442 over 5 yearsAnd if i want to refresh a part of page, then how can i do that ?