Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force view to reload in ionic2 framework

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.

like image 214
Basit Avatar asked Mar 01 '16 13:03

Basit


People also ask

How do you refresh an ionic page?

Ionic provides the same by using <ion-refresher> component to add a pull-down feature. The <ion-refresher> component provides pull-to-refresh functionality on a content component. An Ionic allows a user to use this pattern on a list of data using touch to retrieve more data.

How do you force ionic to refresh a page when navigating on the same URL?

If you wish to reload the pages on navigating to the same URL then you can use this configuration under your root module: @NgModule({ imports: [ ... RouterModule. forRoot(routes, { onSameUrlNavigation: 'reload'}) .... ], declarations: [ ... ], bootstrap: [ ... ] })

What is ion refresher?

Refresher provides pull-to-refresh functionality on a content component. The pull-to-refresh pattern lets a user pull down on a list of data in order to retrieve more data. Data should be modified during the refresher's output events.

How do I run an ionic app on localhost?

By default, ionic serve boots up a development server on localhost . To serve to your LAN, specify the --external option, which will use all network interfaces and print the external address(es) on which your app is being served. Try the --lab option to see multiple platforms at once. ionic serve uses the Angular CLI.


2 Answers

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);
  }

}
like image 200
maudulus Avatar answered Sep 18 '22 16:09

maudulus


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();

like image 22
Siddharth Pandey Avatar answered Sep 22 '22 16:09

Siddharth Pandey