title: Execute function before page is rendered
body: <p>I am using angular.js and I'm trying to check has session been created on server side, and if not I want to redirect to login page.</p>
  
  <p>Problem is that redirection occurs a few second after page is loaded, but I would like to execute function before the page is loaded.</p>
  
  <p>Any suggestions how to achieve this?</p>
  
  <p>Here is my controller:</p>
  
  <pre><code>myPanel.controller('globalController', function($scope, $http){
       $http.get('../classes/login.php').then(function(response){
               $scope.isSession = response.data;
               if($scope.isSession.isStarted === false){
                   window.location = 'http://localhost/PDP/admin';
               }
          });
   });
  </code></pre>