2017-10-18 136 views
0

我想打印一些變量中的數據。我的代碼是:在Angular2中打印數據

public printData(data) { 
     let printContents, popupWin; 
     printContents = data; 
     popupWin = window.open('', '_blank','resizable=yes,top=0,left=0,height=100%,width=auto'); 
     popupWin.document.write(` 
     <html> 
      <head> 
      <title>Print</title> 
      </head> 
      <body onload="window.print();window.close()">${printContents}</body> 
      </html>` 
    ); 
    popupWin.document.close(); 
} 

它工作正常,但我得到的是這樣的:

enter image description here

,我不希望希望後面的打印機選項窗口。我想只顯示用戶:

enter image description here

有沒有辦法做到這一點?

預先感謝您。

+1

你可以做到這一點使用'iframe'看看這個帖子https://stackoverflow.com/questions/9616426/javascript-print-iframe-contents-only - 接受的答案可能是你正在尋找的 –

+0

我試過了,它可以工作。謝謝您的回答。 – Yckeb

+0

NP ..高興地幫助 –

回答

1

你可以使用一個IFRAME,切記不要window.open在這種情況下使用...