【发布时间】:2021-12-14 11:02:29
【问题描述】:
我有问题。我第一次尝试根据金额选择一个复选框。我为此应用了 [checked] 功能。但是在那之后(更改)不起作用你知道为什么吗?
这是 html 的代码:
<mat-radio-group (change)="radioButtonOnChange($event)" formControlName="anticipatedPaymentOrInstallmentAdvance">
<td td-data-table-cell>
<mat-radio-button id='anticipatedPayment' value="ANTICIPATED_PAYMENT" [checked]="isTwiceInstallment()">
{{ 'Anticipated Payment' | translate }}
</mat-radio-button>
</td>
<td td-data-table-cell>
<mat-radio-button id='installmentAdvance' value="INSTALLMENT_ADVANCE" [checked]="!isTwiceInstallment()" [disabled]="disableInstallmentAdvance">
{{ 'Installment Advance' | translate }}
</mat-radio-button>
</td>
</mat-radio-group>
这是 TS 的代码
isTwiceInstallment() {
const overPaidAmount = this.transactionTotal - +this.nextPayment;
const isOverPaid = overPaidAmount > 0.00;
const isTwoTimesInstallment = this.transactionTotal >= (2 * +this.nextPayment);
if (isTwoTimesInstallment && isOverPaid) {
this.form.get('anticipatedPaymentOrInstallmentAdvance').setValue('ANTICIPATED_PAYMENT');
this.disableAnticipatedPaymentDropDown = false;
return true;
} else {
this.form.get('anticipatedPaymentOrInstallmentAdvance').setValue('INSTALLMENT_ADVANCE');
this.disableAnticipatedPaymentDropDown = true;
return false;
}
}
radioButtonOnChange(event: any) {
if (event.value === 'ANTICIPATED_PAYMENT' ) {
this.disableAnticipatedPaymentDropDown = false;
this.form.get('anticipatedPaymentOrInstallmentAdvance').setValue(event.value);
}
if (event.value === 'INSTALLMENT_ADVANCE') {
this.disableAnticipatedPaymentDropDown = true;
this.form.get('anticipatedPaymentOrInstallmentAdvance').setValue(event.value);
}
}
【问题讨论】:
标签: angular angular-material angular-directive