Call function on entering a page, not on going back


#1

Hey there,

Is there a way to trigger a function in the controller for a state when navigating to that state, but not when going back?

For example: say you select a page with a list, function triggers. You select an item from that list which leads to a detailed view. You go back by using the back button, now the function doesn’t trigger.

Any idea?


#2

You could set something up by storing a key in local storage when you first visit the page. Then when you navigate to that page again, check to see if that values exists so you can decided when to execute the function again.


#3

I see what you mean @mhartington - but wouldn’t you then also need to clear that value sometime? Otherwise it will become set after one time that you visit a detailed view, which would sort of defeat the purpose?


#4

Yes you would. Basically what it comes down to is that angular destroys a scope when you navigate away from a view. So there’s no way to easily do this.

But we are doing some work to try to make this possible…

https://github.com/driftyco/ionic/issues/1360


#5

Ah yes- Can’t wait for that one. How is the testing infrastructure coming along?


#6

Andy would be the best person to ask about that.