title: How to wait for api call to complete when called in ngOnDestroy function?
body: <p>I have a scenario where i have to send data to api (database) before specific component is destroyed. As its described in angular2 life cycle, one method is executed before component is destroyed and its called <code>ngOnDestroy</code>. But as specified in documentation, that is an void function so it does not wait for some results to return.</p>
  
  <p>My quesiton is how can i perform my call to api in ngOnDestroy function and wait while it completes?</p>
  
  <p>If i just call update function it works, but when i route from one component to another, the data from first component are not yet updated while next component loads old data (if i hit refresh then i get new data). So problem is that i cannot wait for update function to execute fully and then allow component destruction and routing to next component which will load correct, updated data:</p>
  
  <pre><code>updateData(data: any, callback?: Function) {
      this.apiService.update(data).then(response =&gt; {
          callback(response);
      }
  }
  
  ngOnDestroy() {
      this.updateData(this.data);
  }
  
  // Maybe i could somehow use callback functionality to postpone execution of ngOnDestroy function
  ngOnDestroy() {
      this.updateData(this.data, response =&gt; {
  
      });
  }
  </code></pre>
  
  <p>Or is there any other way to solve this situation?</p>