title: AngularJS $location not updated properly when using $routeProvider
body: <p>I have an Angular JS application with a <code>defaultController</code> which controls the header of the app. Then I have some other controllers one for each view. The views are loaded in the <code>&lt;main&gt;</code>. I load the views using the <code>$routeProvider</code> with this code:</p>
  
  <pre><code>myapp.config(['$routeProvider',
      function($routeProvider) {
          $routeProvider.
              when('/login', {
                  templateUrl: 'templates/login.html',
                  controller: 'loginController'
              }).
              when('/dashboard', {
                  templateUrl: 'templates/dashboard.html',
                  controller: 'dashboardController'
              }).
              ...
  </code></pre>
  
  <p>I am trying to display a LOGOUT button inside the header when the loaded view is the dashboard and hide it if the loaded view is the login view. In order to do that I have on the <code>defaultController</code> the <code>$location</code> object and I properly add and remove classes from the LOGOUT button with <code>ng-class</code>.</p>
  
  <p>There is only one problem: $location gives me the correct path the first time I load the page, but after I change the view (changed by the <code>$routeProvider</code>) that variable is not updated anymore, so when I am actually on <code>/#/dashboard</code> , the <code>$location.url</code> is still on <code>/login</code>. Here the controller code:</p>
  
  <pre><code>controllers.controller('defaultController', ['$scope', 'ipCookie', '$location', function($scope, ipCookie, $location) {
      $scope.url = $location.url();
      ...
  </code></pre>
  
  <p>I also tried with <code>$window.location.hash</code> with the same result.</p>
  
  <p>Any idea?</p>
  
  <p>EDIT: after the accepted answer this is what I ve added on the <code>defaultController</code> in order to make it work</p>
  
  <pre><code>$scope.$on("$locationChangeSuccess", function() {
          $scope.url = $location.url();      
      });
  </code></pre>