Reputation: 16629
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 ?
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
search tab
search tab
)home tab
(without loading the search results in the search tab
itself)I hope that makes my requirement bit clear
Upvotes: 1
Views: 910
Reputation: 44669
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).
Upvotes: 1
Reputation: 199
I believe ngOnInit()
is what you're looking for. Anything that you put inside of that function will be called every time that the page is initialized (and only after receiving its data-bound properties).
Further reading: https://angular.io/docs/ts/latest/api/core/index/OnInit-class.html
Hope that was what you were looking for :)
Upvotes: 1