title: Angular2: Retrieve FileReader result with a Promise
body: <p>On my view, there is an input file linked with one function of a controller</p>
  
  <pre><code>&lt;input type="file" style="display: none;" (change)="importXML($event)"&gt;
  </code></pre>
  
  <p>This function call a function in a service which suppose to convert my xml file to a json</p>
  
  <pre><code>importXML(event): void {
          const obj = this.myService.convertXML2Json(event.target);
  }
  </code></pre>
  
  <p>In the service function, the XML file is read in a FileReader and then converted
  to xml in the onloadend part of the file reader</p>
  
  <pre><code>convertXML2Json(event): any {
      const file = event.files[0];
      const fr = new FileReader();
      fr.onloadend = e =&gt; xmltoJsonFunction(fr.result);
      fr.readAsText(file)
  }
  </code></pre>
  
  <p>How can I retrieve the converted json result inside onloadend to use it in the Angular controller, specifically with a Promise ? Or should I use a setTimeout ? </p>