title: How to wait for response of another method having subscribe call inside
body: <p>I have created a FileUploadService in angular which is uploading my file to server. But now the issue is when I am calling the method it is not waiting for response. My code is:</p>
  <p>File Upload Service Code:</p>
  <pre><code>uploadToServer(file: File) {
      const fileModel: FileModel = { fileId: '', name: ''};
      this.fetchToken().subscribe(token =&gt; {
          this.postFile(file, token).subscribe(event =&gt; {
              if (event.type === HttpEventType.UploadProgress) {
                  const uploadPercent = event.loaded / event.total * 100;
              } else if (event.type === HttpEventType.Response) {
                  const key = 'id';
                  fileModel.name = file.name;
                  fileModel.fileId = event.body[key].toString();                   
                  console.log('File uploaded:- ' + file.name);
              }
          });
      });
      return fileModel;
  }
  fetchToken() {
      return this.httpClient.get('url');
  }
  
    postFile(file: File, token: any) {
      const folderID = '12345';
  
      const header = new HttpHeaders({
          Authorization: 'Bearer ' + (token.access_token)
      });
      const form = new FormData();
      const metadata = {
          name: (file.name), 
          mimeType: (file.type), 
          parents: [folderID], 
      };
      form.append('metadata', new Blob([JSON.stringify(metadata)], {
          type: 'application/json'
      }));
      form.append('file', file);
      return this.httpClient.post('url', form, {
          headers: header,
          reportProgress: true,
          observe: 'events'
      });
  }
  </code></pre>
  <p>My Component:-</p>
  <pre><code>onFileChange(event) {
  if (event.target.files.length &gt; 0) {
    const file = event.target.files[0];
    const response = this.fileUploadService.uploadToFile(file);
    console.log(response.fileUrl);
    this.formAgent.get('image').setValue(response.Id);
  }
  }
  </code></pre>
  <p>Here the response is not getting any value.</p>