title: Chain multiple promises in Angularjs
body: <p>I have the following structure and need to simplify it,</p>
  
  <p>Resuable service1 to interact with IndexedDB</p>
  
  <pre><code>function isDbExist (){
  // do something , it return either reject or resolve
  }
  
  function createDB (){
  // do something , it return either reject or resolve
  }
  
  function getData (){
      // do something , it return either reject or resolve
  }
  </code></pre>
  
  <p>In another service2 I'm injecting this service1 and using the functions as such</p>
  
  <pre><code>function1 (){
  service1.isDbExist.then(function(data){
     service1.createDB.then(function(data){
        service1.getData.then(function(data){
          referred.resolve(data);
        },function(error){
         deferred.reject(error)
        })
     },function(error){
      deferred.reject(error);
     })
  },function(error){
     deferred.reject(error);
  })
  }
  </code></pre>
  
  <p>The problem here is the readability of the code is not good, its not easy to debug as which reject function is for which promise. Is their some good way of doing this ? I have read about $q.all but don't this its applicable in this situation.</p>