sameera207 sameera207 - 6 months ago 40
TypeScript Question

A the function that triggers always when displaying a component in an ionic2

What would be the function that triggers always when displaying a component in an ionic2 app.

E.g As I noticed

function in a component triggers only when the component is initialize for the first time or when you do a
from a different page.

But constructor will not trigger when clicking the
button or switch between

Is there any method that will call every time when the component is displayed on the screen ?


After doing some research (big word for googling ;)) I realize that each tab is keeping its own history stack. E.g If I have two tabs
what ever push, pop I do in the
table is independent from the
home tab

So what I want to do is

  • Do a search in
    search tab

  • Click search button (
    search tab

  • Should redirect to
    home tab
    (without loading the search results in the
    search tab

I hope that makes my requirement bit clear


You can use the ionViewDidEnter event on the result tab page. That method gets executed everytime the page is entered, so within that method, you could get the result from a previous query back from the service.

Please take a look at this plunker

In the page2.html file, (which would be your home tab) I've included this:

    this.result = this.tabService.result;

So everytime the user enters in that page, we could get the result from the service again (if the user didn't fill out the query fields in the previous tab, the results from the previous query will be used).