title: How to call function itself inside a function in my case
body: <p>I am trying to call the function itself within the function. </p>
  
  <p>Basically it will call the function itself to make another request if the first request has the id.</p>
  
  <p>I have something like</p>
  
  <pre><code>function test(variable) {
      var q = $q.defer();
      $http({
             method: 'get',
             url: 'myurl.com'
          }).then(function(returnData) {
              if(returnData.getNewInfo) {
                  test(returnData.id).then(function(secondData){
                     q.resolve(secondData);
                  })
              } else {
                     q.resolve(returnData)
              }    
          });            
      }
      return q.promise;
  }
  </code></pre>
  
  <p>I am getting 
  <code>test(...).then</code> is not a function error in the console on this line</p>
  
  <pre><code> test(returnData.id).then(function(secondData){
  </code></pre>
  
  <p>I am trying to call the function itself inside the promise. Not sure how to fix my issue. Can anyone help me about it? Thanks a lot!</p>