title: Angular + UI Router, changing title on $stateChangeSuccess (event fires too early?)
body: <p>I implemented a custom page title according to ngBoilerplate:</p>
  
  <p><a href="https://github.com/ngbp/ngbp/blob/v0.3.1-release/src/app/app.js" rel="nofollow">https://github.com/ngbp/ngbp/blob/v0.3.1-release/src/app/app.js</a></p>
  
  <pre><code>.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {
    $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
      if ( angular.isDefined( toState.data.pageTitle ) ) {
        $scope.pageTitle = toState.data.pageTitle + ' | ngBoilerplate' ;
      }
    });
  })
  </code></pre>
  
  <p>So basically, the title changes on each <code>$stateChangeSuccess</code> event. The problem is, that in my browser history, it saves the new title as the title of the last page. So for instance if I am at a page with the title "Home" and navigate to a page with the title "About", my history will show "About" as last item, but navigate correctly to "Home" when I click on it. I fear that this will really confuse people.</p>
  
  <p>So I came up with a "hack", that seems to solve this problem:</p>
  
  <pre><code>.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {
    var nextTitle = "";
  
    $scope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
      $scope.pageTitle = nextTitle;
    });
  
    $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
      if ( angular.isDefined( toState.data.pageTitle ) ) {
        nextTitle = toState.data.pageTitle + ' | ngBoilerplate' ;
      }
    });
  })
  </code></pre>
  
  <p>So now, the title will be save in a variable first and will be assigned to the scope only on <code>$locationChangeSuccess</code>. This seems to work, but I don't know how reliable this is.</p>
  
  <p>So my question is, I guess, how to do this correctly. How do I get a reliable changing page title, that gets it's data from the current state?</p>
  
  <p>And furthermore out of interest: Why doesn't it work with <code>$stateChangeSuccess</code>? Is there a reason why this event fires so early?</p>