【发布时间】:2021-10-16 22:51:36
【问题描述】:
当我从选择下拉列表中选择一个值时,我只能打印 ID,但我想显示 Description 而不是 Id。我只想显示名称,但我想将选定的值 Id 发送到 API。
component.ts
pay = [];
paymentForm = new FormGroup({
paymentType: new FormControl('', []),
description: new FormControl('', []),
amount: new FormControl('', []),
});
btnAddToPayment(payment: SalePayment) {
this.cartService.addToPaymentCart(payment);
this.pay.push(this.paymentForm.get('paymentType').value);
}
用于选择的 HTML
<select formControlName="paymentType" class="mb-3 form-control" id="Payment">
<option value="" disabled selected>Payment type</option>
<option *ngFor="let pay of selectPayment" [value]="pay.Id">
{{pay.Description}}
</option>
</select>
btnAddToPayment 的 HTML
<div class="input-group-prepend">
<span class="btn btn-default input-group-text" (click)="btnAddToPayment(paymentForm.value)">
<i class="fa fa-plus-square" style="color: green"></i>
</span>
</div>
表格
<tr *ngFor="let paym of payment">
<!-- <td>{{paym.paymentType.Description}}</td>-->
<td>{{paym.paymentType}}</td>
<td>{{paym.amount | currency:'RS: '}}</td>
<td>{{currentDate | date:'yyyy-MM-dd'}}</td>
</tr>
界面
export class SalePayment {
SaleId: string;
PaymentTypeId: number;
Description: string;
Amount: number;
Balance: number;
}
- 我想将选定的值推送到数组并将它们保存到数据库。可能有多次付款。
【问题讨论】:
标签: angular angular8 angular9 angular11