title: Angular : pass parameter to controller from $routeProvider.when
body: <p>I perform a routing upon a broadcast and I need to pass a parameter from $rootScope.$on to a controller through routing.</p>
  
  <pre><code>$rootScope.$on('unauthorized_access', function (event, args) {
      $location.path('/login:' + args.msg);
  });
  </code></pre>
  
  <p>Now, this is working.</p>
  
  <pre><code>$routeProvider
  .when('/', {
      templateUrl: 'mainApp/landingPage/login.html'
  })
  .when('/login::msg', {
      templateUrl: function(params) {
          if (params) {
              // The params can be printed in console from here...
              console.log(params);
          }
          return 'mainApp/landingPage/login.html';
      },
      controller: 'loginController'
  })
  .otherwise({
      redirectTo: '/'
  });
  </code></pre>
  
  <p>Now, so far it seems okay. But I need to pass the params to loginController. I tried, </p>
  
  <pre><code>.when('/login::msg', {
      templateUrl: function(params) {
          if (params) {
              console.log(params);
          }
          return 'mainApp/landingPage/login.html';
      },
      controller: 'loginController',
      pageParams : params
  })
  </code></pre>
  
  <p>but I think, I am doing it wrong. Please help me. Any helps is appreciated. Thank you.</p>
  
  <p>EDIT : I will add a scenario. I need to pass a message-string to loginController from any screen when the 'token' becomes invalid after a fixed time and user is redirected to login screen. Now, when the user arrives for the first time, there is no message to be shown.
  Hence, this is how I pass the message to broadcast</p>
  
  <pre><code>$rootScope.$broadcast('unauthorized_access', param);
  </code></pre>