title: AngularJS, $routeProvider and resolve: Hello World example not working
body: <p>I'm trying to put together a Hello World example of <code>$routeProvider</code> using <code>resolve</code> to feed data into the controller. <a href="http://plnkr.co/edit/8363ZkIJP1ii7aIrfrM7?p=preview" rel="nofollow">This is the plunk</a>; the error I get is <code>Unknown provider: greetingService</code> however the factory is declared before the controllers and the config. What's wrong with this code?</p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;body ng-controller="mainCtrl"&gt;
  
     &lt;a href='#option1'&gt;click me to show Hello World&lt;/a&gt;
  
     &lt;br/&gt;&lt;br/&gt;
  
     {{message}}
  
     &lt;br/&gt;&lt;br/&gt;
  
     *****
  
     &lt;div ng-view&gt;&lt;/div&gt; 
  
     *****
  
  
  &lt;/body&gt;
  </code></pre>
  
  <p>template.html:</p>
  
  <pre><code>&lt;div ng-controller="templateCtrl"&gt;
     {{hello}}
  &lt;/div
  </code></pre>
  
  <p>app.js:</p>
  
  <pre><code>angular.module('app', ['ngRoute']);
  
  
  angular.module('app')
  .factory("greetingService", function($q, $timeout){
     return {
         getGreeting: function(){
             var deferred = $q.defer();
             $timeout(function(){
                 deferred.resolve("Hello");
             },1000);
             return deferred.promise;
         }
     };
  });
  
  
  angular.module('app')
  .controller('mainCtrl', function($scope) {
  
       $scope.message = "Message in the main controller";
  });
  
  angular.module('app')
  .controller('templateCtrl', function($scope,greeting) {
  
      $scope.hello = greeting + " World";
  
  });
  
  angular.module('app')
  .config(function($routeProvider,greetingService) {
  
      $routeProvider.
        when('/option1', {
  
          templateUrl: 'template.html',
          controller: 'templateCtrl',
          resolve: {
              greeting: function(greetingService){
                  return greetingService.getGreeting();
              }
          }
  
        });
    });
  </code></pre>