title: How can I pass an object through $stateParams?
body: <p>I've got a ui-router application with a large number of states, and I need to be able to pass a model through $stateParams.  On every $http request, I check the response for a "STATE" parameter, which is returned from the server. If it exists, I execute <code>$state.go(STATE)</code>.  </p>
  
  <p>So effectively, I've got my <code>$stateProvider</code>:</p>
  
  <pre><code>$stateProvider
      .state('Account', {url: '/Account', template: '&lt;ui-view/&gt;'})
      .state('Account.name', {
          url: '/Name',
          templateUrl: 'app/Account/partials/Name.html',
          controller: 'AccountNameController as nameVm'
      })
  </code></pre>
  
  <p>And many more states that look just like this.  </p>
  
  <p>I have a data model that is just a factory with an object that is get and set via functions.  So whenever I call saveAccount(), it takes the model and sends it to a Web API backend.  The backend verifies the data and sends it back with a STATE parameter (either <code>account.invalid</code>, <code>account.valid</code>, or <code>account.needsMoreInfo</code>).  Here's my $httpInterceptor</p>
  
  <pre><code>.factory('httpInterceptor', ['$q', '$injector',
          function ($q,$injector) {
              return {
                  'response': function(response) {
                      if(response.data.state){
                          $injector.get('$state').go(response.data.state, response.data.account);
                      }
                      return response;
                  }
              };
          }
      ])
  </code></pre>
  
  <p>As you can see, I'm trying to send the account through the stateparams. </p>
  
  <p>In the controller, I basically need to be able to say <code>vm.account = $stateParams.account</code></p>
  
  <h2>My question is:</h2>
  
  <p>How can I modify my $states to both have a named controller and also take a state parameter and access that from the controller?  </p>
  
  <p>The reason I'm not passing the data through a service is because there are multiple models, so I can't just provide the name of the service in the $httpInterceptor because it isn't constant.  </p>
  
  <h1>EDIT: Figured it out</h1>
  
  <p>Here's what my controller needed to have in it: 
      if ($stateParams &amp;&amp; $stateParams.data){
                  vm.Account = $stateParams.data;
              }</p>
  
  <p>And here's what the state ended up looking like:</p>
  
  <pre><code>.state('taxAccount.invalid', {
              url: '/Invalid?params',
              templateUrl: 'app/TaxAccount/partials/Invalid.html',
              controller: 'taxAccountInvalidController as invalidVm',
              params:{data:null}
          })
  </code></pre>
  
  <p>I didn't realize I could put <code>params:{data:null}</code>.  I thought the stateParams had to go in the controller declaration in the state configuration. </p>