title: AngularJS : Pass data to state with $state.go in angular-ui-router
body: <p>I'm making a document editor. Documents can be Type A or Type B.  They are accessed by url by document id, but the id does not make it clear if the document is of type A or B.</p>
  
  <p>So, I need to load the document by id, determine its type from its data, and then pass it to either the TypeAController or TypeBController.</p>
  
  <p>Right now, with ui-router, I have something like this:</p>
  
  <pre><code>$stateProvider
  .state('loading', {
      url: '/{documentId}',
      template: 'Loading...',
      controller: function ($stateParams, $state) {
          loadDocument($stateParams.documentId)
              .then(function (loadedDocument) {
                  if (loadedDocument.type === 'A') {
                      $state.go('EditA');
                  } else if (loadedDocument.type === 'B') {
                      $state.go('EditB');
                  }
              })
      }
  })
  .state('A', {...})
  .state('B', {...})
  </code></pre>
  
  <p>The loading state loads the document, determines its type, and then goes to the next state.</p>
  
  <p>Frustratingly, though, I can't find a way to actually pass the loaded document to the next states!  I can make a globalish service into which I can insert the document, or I can just pass the id of the document along and load it again in each state (hopefully from a cache this time), but these methods are so clunky and everything else about angular and angular-ui has been so smooth.</p>
  
  <p>Any suggestions?</p>