Ionic/Angular controller loading only once on startup

So, I have this app Im working on and each time I come back to a page it reloads the whole controller, normally this is fine. However, in this case, I only want it to load one time, unless something else happens. My solution, which may not be the best but seems to work well for this prototype, is to use a root scoped variable.

if (!$rootScope.loaded)

{

//load this on startup then set to loaded

alert(‘This is the first loading’)

$rootScope.loaded = true;

}

Now, when I use the Back button it does not reload that part. But, in another page I can always set the $rootScope.loaded to false and recall the loading.

I would love to know if there is another way, or better way, to do this.

Leave a comment