4

I have a requirement where I have refresh the contents of the current page onclick of the refresh button in the current page.I went through few websites but I am not quite clear about this functionality.Could anyone suggest me how to do this?

2
  • 1
    Can yopu add your code and what you have tried so far? Commented Apr 28, 2017 at 14:35
  • post your code and be more specific. What do you need to reload? Is it the content of the page? In this page do you make and api call or something like this? Use a refresher, it's better, it's cleaner, has a better UX. Commented Apr 28, 2017 at 15:17

4 Answers 4

8

Onclick of your refresh button, you could call the page event method ionViewWillEnter()

From the official docs --> ionViewWillEnter() Runs when the page is about to enter and become the active page.

HTML

<button (click)="refreshPage()">Refresh Page</button>

Typescript

    ionViewWillEnter(){
            this.myDefaultMethodToFetchData();
        }

    refreshPage() {
        this.ionViewWillEnter();
    }

    myDefaultMethodToFetchData(){
        ...Do Something, when the page opens...
    }
Sign up to request clarification or add additional context in comments.

1 Comment

this is worked for me ... easy to reuse ... very simple and fast solution. tnx
0

This will work!!! Give this under the function that's called on button click event.

this.navCtrl.setRoot(this.navCtrl.getActive().component);

or

Use the ionViewWillEnter lifecycle event on your page. You can put the correct code in that method to refresh all the necessary things on your page. https://ionicframework.com/docs/api/navigation/NavController/

Comments

0

Add this in the constructor and just replace your page name

    this.navigationSubscription = this.router.events.subscribe((e: any) => {
           if (e instanceof NavigationEnd && e.url === '/page-name' && localStorage.getItem('prevUrl') === '/page-name') {
            this.ionViewWillEnter();
            this.ngOnInit
           }
        });

Comments

-1

Try this: Just pop one page and then push that page again. Hope this will help :)

this.navCtrl.pop(); this.navCtrl.push(NewPage);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.