title: Exporting data to a file in Angular2
body: <p>In an angular2 application (rc1) I store some data in localstorage. I want to give the user the possibility to store the data in a file and import it on a different system or browser. It was hard to find out how to do this, because of sanitization. Finally I came to this solution.</p>
  
  <pre><code>import { DomSanitizationService } from '@angular/platform-browser';
  import { UserdataService } from '../shared';
  export class ExportComponent {
    constructor(private userdata: UserdataService, sanitizer:DomSanitizationService) {
     let dataString = JSON.stringify(userdata.getDataObject());
     let blob = new Blob([dataString], { type: 'application/json' });
     this.downloadurl =
         sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob));
  }
  </code></pre>
  
  <p>which I used in a template</p>
  
  <pre><code>&lt;a [href]="downloadurl" download="data.json" &gt;Download&lt;/a&gt;
  </code></pre>
  
  <p>I found the sanitizer and its method bypassSecurityTrustUrl by guessing and grepping in @angular/platform-browser/src/security/dom_sanitization_service.d.ts. I could not find any documentation for it.</p>
  
  <p>Is this the right way to tackle this problem? If I leave out the call to bypass the security trust, the URL gets prefixed by <code>unsafe:</code>, which makes it non-functional. Is there some documentation that I missed?</p>