title: Angular $q promise Error: object is not a function
body: <p>I have a factory method which has $http(async task) so i used $q promise and the following error has occurred <code>TypeError: object is not a function</code> @line: return $q(funtion....)</p>
  
  <p>written using <strong>Promise API:</strong></p>
  
  <pre><code>service.fetch = function(query) {
      return $q(function(resolve, reject){
          $http({ url: srcset[query], method: 'GET'}).success(function(db){
              resolve(db);
          });
      });
  };
  </code></pre>
  
  <p>but if written with <strong>Deferred API:</strong></p>
  
  <pre><code>service.fetch = function(query) {
      var deferred = $q.defer();
      $http({ url: srcset[query], method: 'GET'}).success(function(db){
          deferred.resolve(db);
      });
      return deferred.promise;
  };
  </code></pre>
  
  <p>It works fine</p>
  
  <p>I have written exactly as mentioned in <a href="https://docs.angularjs.org/api/ng/service/" rel="nofollow">https://docs.angularjs.org/api/ng/service/</a>$q</p>
  
  <p>Can anyone point out where have i gone wrong.</p>