title: Getting the name of a state in its `onEnter` hook
body: <p>I'm building an application where I want to toggle a property in a service the moment a user enters and leaves a route. To do this I need to know about the state's name in the <code>onEnter</code> and <code>onExit</code> hooks. This is relatively easy for the <code>onExit</code> hook since I can just inject the <code>$state</code> service and read the name of the current state. But since the current state has not been set yet when the <code>onEnter</code> hook is called there is no way of knowing what the state we're transitioning to.</p>
  
  <p>I still need to to have fine control over other parts of the state so I'd rather not have any for loops. I'm looking for a way to be able to pass the <code>onEnter</code> function to the state, whilst still retrieving the state's name inside of the function itself.</p>
  
  <p>Here is the code I've written:</p>
  
  <pre><code>function onEnter($state, Steps) {
    var stateName = $state.current.name; // Not possible. The current state has not been set yet! 
    var step = Steps.getByStateName(stateName);
  
    step.activate();
  }
  
  function onExit($state, Steps) {
    var stateName = $state.current.name; // No problem. We know about the state. 
    var step = Steps.getByStateName(stateName);
  
    step.deactivate();
  }
  
  $stateProvider
    .state('step1', {
      url: '/step1',
      templateUrl: 'templates/step1.html',
      controller: 'StepOneController',
      onEnter: onEnter,
      onExit: onExit
    });
  </code></pre>
  
  <p>My solution I'm using for now is to use a factory to create context for the <code>onEnter</code> function passed to the state. This is far from ideal because I still need to pass the state's name to it.</p>
  
  <p>Here is an example of said workaround:</p>
  
  <pre><code>function onEnterFactory(stateName) {
    return function onEnter(Steps) {
      var step = Steps.getByStateName(stateName);
  
      step.activate();
    }
  }
  
  $stateProvider
    .state('step1', {
      url: '/step1',
      templateUrl: 'templates/step1.html',
      controller: 'StepOneController',
      onEnter: onEnterFactory('step1')
    });
  </code></pre>