title: AngularJS - Dynamic $StateProvider
body: <p><em>I am eagerly trying to create a dyanmic $StateProvider:</em></p>
  
  <p><strong>Standard static $StateProvider:</strong></p>
  
  <pre><code>    $stateProvider
        .state('main',
        {
          url: '/',
          templateUrl: '/views/main.html',
          controller: 'MainCtrl'
        })
        .state('login',
        {
          templateUrl: '/views/login-form.html',
          controller: 'LoginCtrl'
        })
        .state('logout',
        {
          controller: 'LogoutCtrl'
        })
        .state('sales', {
          templateUrl: '/views/sales-data.html',
          controller: 'SalesDataCtrl',
          resolve: {
            user: 'User',
            authenticationRequired: function(user) {
              user.isAuthenticated();
            }
          }
        });
  </code></pre>
  
  <p><strong>Dynamic $StateProvider:</strong></p>
  
  <pre><code>var verify = function(user) { user.isAuthenticated(); };
  
  var states= [
  { name: 'main', url: '/', templateUrl: '/views/main.html', controller: 'MainCtrl' },
  { name: 'login', url: '', templateUrl: '/views/login-form.html', controller: 'LoginCtrl' },
  { name: 'logout', url: '', templateUrl: '', controller: 'LogoutCtrl' },
      {
          name: 'sales',
          url: '',
          templateUrl: '/views/sales-data.html',
          controller: 'SalesDataCtrl',
          //resolve:
          //[
          //    { user: 'User', authenticationRequired: 'verify();' }
          //]
      }
  ];
         // w/o the array brackets in resolve the navigation does not work.
         // with the array brackets, once sales is clicked I get:
         // Error: [ng:areq] Argument 'fn' is not a function, got Object
  </code></pre>
  
  <p><strong>The two methods below work as long as I am not using resolve:</strong></p>
  
  <pre><code>  This works:
     angular.forEach(states, function(state) {
          $stateProvider.state(state);
      });
  
     This works:
     angular.forEach(states, function(state) {
          $stateProvider.state(state.name, state);
      });
  </code></pre>
  
  <p><strong>Question:</strong> How can I make this dynamic $StateProvider work with the resolve?</p>