【发布时间】:2022-02-01 16:57:09
【问题描述】:
我有一个angular application,其中包含发票功能。 我使用引导模式来设计发票,您可以在下面的图片 "before print" 中看到它。在这张图片中,我在发票中添加了 2 项,但是当我继续使用 window.print() 打印发票模式时,我看到打印页面没有获取输入元素的全部值。
例如对于发票页面中的第一项,您可以看到输入为“Some Item - Black Color E Series 56565”的值,但在打印页面@ 987654328@ 仅将部分值设为“Some Item - Black Color E Se”,其余部分被隐藏。
页面左下角的“旁白”输入字段也会出现同样的情况。我们如何解决这个问题?
Note: I've used HTML input element for item as well as narration fields on an invoice page.
为了帮助您更多,我可以为您提供一些必要的代码库来理解这一点。看看代码,以及下面的两张图片。
1. Angular 组件代码库
// this print method is called on click of Save & Print button
print() {
// first save the invoice and if save is successfull then give a print command
this.invoiceService.create(this.invoice)
.subscribe(
result => {
console.log(result);
if(result) window.print(); // print the invoice only if it is successfully saved
},
(error: AppError) => {
this.error = true;
this.errorMsg = 'Error occurred.';
return ;
});
}
2。 Style.css 代码库
@media print {
html, body {
height:100vh;
margin: 0 !important;
padding: 0 !important;
overflow: hidden;
}
body * {
visibility:hidden;
}
#printThis, #printThis * {
visibility:visible;
}
.remove-item, .add-item, .modal-footer {
display: none;
}
.hide-discount, .hide-freight {
display: none;
}
.modal {
position: absolute;
left: 0;
top: 0;
margin: 0;
padding: 0;
overflow: visible!important;
}
}
3. HTML 标记:
<div class="row">
<div class="items-table">
<ng-container *ngFor="let item of items; let i=index;">
<div class="row invoice-items" >
<div class="col-4 input-container">
<input [(ngModel)]="item.description" name="itemDescription" id="item" type="text" placeholder="Item name" >
</div>
</div>
</ng-container>
</div>
</div>
4.发票页面输入元素的 CSS 样式:
.items-table input {
line-height:1.5em;
}
input:focus {
outline: 0;
}
.col-4.input-container input {
width: 100%;
}
input:hover, textarea:hover, input:focus, textarea:focus {
border: 1px solid #CCC;
}
这是我用于输入元素的最低限度的样式。
【问题讨论】:
-
您需要提供实际发票的一些标记(一个最小示例)。模态在这里并不是真正的问题。这就是它里面的所有标记。
-
好的,为您提供一个 Item Name 输入字段标记以及我发票页面中输入元素的整个 css 代码库。
-
@disinfor 请查看上面更新的问题,现在可以使用所需的标记和 CSS 样式代码。