In a single angular component I wish have a print button which when the user clicks, will print a single div
from my component's template.
I know this answer works, I've tried it. But I do not like how I need to reapply all styles or rewrite all the styles in the <style>
head tags.
I really like this answer but I can't get it to work. I think it might have something to do with how classes are renamed after the app has been served/built.
This is how I've implemented the above answer but can't get it to work.
component.ts
onPrint() {
window.print();
}
component.html
<div class="print">
<button (click)="onPrint()">Print</button>
all the stuffs I want to print
</div>
component.scss
@media print {
:not(.print) {
display: none !important;
}
}
How can I get the above answer to work resulting as little code as possible, and retaining the styles applied to the front-end?
I realize how similar the question is to this one but this question was asked almost two years ago and with regards to angular 2. Not quite sure how different it is with regards to angular 6.