Reputation: 73
<head>
<script>
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
`
How I can use this script in my component class method.I want when My button is clicked my above script is run but I don't know how manipulation DOM in Angular 2
Upvotes: 0
Views: 368
Reputation: 9648
You do not need to wrap it within a script
HTML tag, just call that function (implemented in your TS file) once the button is clicked, something like: <button (click)="printContent()">print</button>
.
If you're looking for print stuffs, that answer could help you.
Upvotes: 1