title: AngularJS defer error: Argument 'fn' is not a function, got Object
body: <p>I'm attempting to make my app gather the data before changing the route, as shown on many a video from John Lindquist: <a href="http://www.youtube.com/watch?v=P6KITGRQujQ&amp;list=UUKW92i7iQFuNILqQOUOCrFw&amp;index=4&amp;feature=plcp">http://www.youtube.com/watch?v=P6KITGRQujQ&amp;list=UUKW92i7iQFuNILqQOUOCrFw&amp;index=4&amp;feature=plcp</a></p>
  
  <p>I have it all hooked up, but when it's time for the deferred object to resolve, i get the error: </p>
  
  <pre><code>Error: Argument 'fn' is not a function, got Object
  at assertArg (http://localhost:9000/components/angular/angular.js:1019:11)
  at assertArgFn (http://localhost:9000/components/angular/angular.js:1029:3)
  at annotate (http://localhost:9000/components/angular/angular.js:2350:5)
  at invoke (http://localhost:9000/components/angular/angular.js:2833:21)
  at Object.instantiate (http://localhost:9000/components/angular/angular.js:2874:23)
  at http://localhost:9000/components/angular/angular.js:4759:24
  at &lt;error: illegal access&gt;
  at Object.Scope.$broadcast (http://localhost:9000/components/angular/angular.js:8261:28)
  at http://localhost:9000/components/angular/angular.js:7417:26
  at wrappedCallback (http://localhost:9000/components/angular/angular.js:6797:59) angular.js:5704
  </code></pre>
  
  <p>My code looks like this:</p>
  
  <p>Route - </p>
  
  <pre><code>angular.module( 'saApp' )
  .config( function ( $routeProvider, $locationProvider ) {
      $routeProvider
          .when( '/dashboard', {
              templateUrl: 'views/dashboard/dashboard.html',
              controller: Dashboard,
              resolve: Dashboard.resolve
          } 
  });
  </code></pre>
  
  <p>controller - </p>
  
  <pre><code>var Dashboard = angular.module( 'saApp' ).controller(
      function ( $scope, dataset ) {
              $scope.data = dataset;
      } );
  
  Dashboard.resolve = {
    dataset: function ( $q, DBFactory ) {
  
      console.log("dataset enter")
      var deferred = $q.defer();
  
      DBFactory.get( {noun: "dashboard"},
          function ( data ) {
              console.log("resolving");
              deferred.resolve( data );
          } );
  
      console.log("promise");
      return deferred.promise;
    }
  }
  </code></pre>
  
  <p>On run, it executes the resolve, the DBFactory resource goes, comes back and everything works up until the actual "deferred.resolve(data);"  which is where then i get the error pasted above. If i comment that one line out, of course i get no page, but i also get no error. </p>
  
  <p>The contents of data, coming back from DBFactory is a JSON object, which is what is expected, and shown in all the examples i've seen online and videos. </p>
  
  <p>using:</p>
  
  <pre><code>AngularJS 1.0.6
  </code></pre>
  
  <p>Thoughts? Thanks for all your help.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>It seems the way i was using my routes and defining the controller with the namespace:</p>
  
  <pre><code>var Dashboard = angular.module( 'saApp' ).controller()
  </code></pre>
  
  <p>was to blame for this. When i simply use a standard function declaration:</p>
  
  <pre><code>function DashboardCtrl($scope, dataset) {
    $scope.data = dataset;
  }
  </code></pre>
  
  <p>it satisfies the "looking for function, got object" error. The weird thing was i changed to using it as an object "var DashboardCtrl = angular.module('saApp').controller()" or even what i had it to prior to that from the yeoman generator, and specified in the angularjs docs of: </p>
  
  <pre><code>angular.module( 'saApp' )
  .controller( 'DashboardCtrl', function ( $scope, dataset ) {});
  </code></pre>
  
  <p>with a route of:</p>
  
  <pre><code>.when( '/dashboard', {
              templateUrl: 'views/dashboard/dashboard.html',
              controller: 'DashboardCtrl'
          } )
  </code></pre>
  
  <p>wouldn't work. </p>