$routeChangeStart demo

@Mistalis Stackoverflow

by Kushal Jayswal

HTML

<script type="text/ng-template" id="partials/foo">
  Foo content
</script>
<script type="text/ng-template" id="partials/bar">
  Bar content
</script>

<div ng-controller="MyCtrl">
  <ul>
    <li><a href="#/foo">Foo</a></li>
    <li><a href="#/bar">Bar</a></li>
  </ul>
  <hr>
  <div ng-view></div>
</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.controller('WidgetsController', function($scope) {});
myApp.controller('MyCtrl', function($scope) {
  $scope.$on('$routeChangeStart', function(scope, next, current) {
    console.log('Changing route from ', current);
    console.log('Going to ', next);
  });
});


myApp.config(function($routeProvider) {

  $routeProvider
    .when('/foo', {
      templateUrl: 'partials/foo',
      controller: 'WidgetsController'
    })
    .when('/bar', {
      templateUrl: 'partials/bar',
      controller: 'WidgetsController'
    })
});