title: Angular2- Enable Print Functionality in the same window on click of a PRINT link
body: <p>In my angular app, I have a component where in the template I have a print link on click of which i have to enable print functionality.I am trying something like this in my HTML-</p>
  
  <pre><code>&lt;div&gt;
  &lt;a href="#" (click)="print()"&gt;PRINT&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and in .ts file-</p>
  
  <pre><code>print(): void {
      let printContents, popupWin;
      printContents = document.getElementById('print-section').innerHTML;
      popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
      popupWin.document.open();
      popupWin.document.write(`
        &lt;html&gt;
          &lt;head&gt;
            &lt;title&gt;Print tab&lt;/title&gt;
            &lt;style&gt;
            //........Customized style.......
            &lt;/style&gt;
          &lt;/head&gt;
      &lt;body onload="window.print();window.close()"&gt;${printContents}&lt;/body&gt;
        &lt;/html&gt;`
      );
      popupWin.document.close();
  }
  </code></pre>
  
  <p>This works but it opens a new window for print. Is there anyw ay , I can have that in same window.
  I also tried-</p>
  
  <pre><code>&lt;a href="javascript:window.print();"&gt;Print&lt;/a&gt;
  </code></pre>
  
  <p>But both of the above approach does not work. Any idea how can i get my page printed in angular2.</p>