How to optimise controllers to make view transition better

I have some tabs, and controller binds to each view, as the controller gets heavy, the view transition doesn’t work very well, sometimes have to tab the screen twice to go to another view. What is the best way to organise my controller code so I can fix this problem?

Is there a way I can execute some of the controller code after the view has been fully loaded?

That’s a very good question. I would like to know this too. My controllers are also causing this problem.

Is there a callback or event we can listen to when the view transition is complete?

Make sure all (or at least most of!) your controller code is async using promises - you can assign any results to watched scope variables. As long as your controller just sets up promises and finishes immediately, your view transitions should also be reasonably quick.

In saying that, if you’re still having issues, try something like this for the really heavy code:

$scope.$on('$viewContentLoaded', function(){
   // This code won't execute until the view is loaded
});
1 Like