Call function on entering a page, not on going back

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?

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.

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?

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…

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

Andy would be the best person to ask about that.