title: How to get the current state name using angularjs
body: <p>I want to get the current state name in my run(). I am using $state.current.name. but its returning empty string. </p>
  
  <pre class="lang-js prettyprint-override"><code>$rootScope.$on('$stateChangeStart', function (event, next) {            
              var json = (function () {
                  event.preventDefault();
                  $.ajax({
                      'async': false,
                      'global': false,
                      'url':'users/testLogin',
                      //'data': 'action=showOrders', 
                      'dataType': "json",
                      'success': function (data) {
                          if(data.success){
                              $rootScope.authenticated = true;
                              $rootScope.id = data.data.id;
                              $rootScope.unique_id = data.data.unique_id;
                              $rootScope.print_house_id = data.data.print_house_id;
                              $rootScope.name = data.data.name;
                              $rootScope.email = data.data.email; 
                              $rootScope.type = data.data.type; 
                          } else {
                              console.log($state.current.name);
  
                          }                        
                      }
                  });
              })(); 
          });
  </code></pre>
  
  <p>Can anyone please find out where is my error.</p>