sameera207 sameera207 - 3 months ago 24
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

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

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


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

Update



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
home
and
search
what ever push, pop I do in the
search
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
    itself)



I hope that makes my requirement bit clear

Answer

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:

  ionViewDidEnter(){
    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).

Comments