我在角度7中有一个复选框
刷新页面时,这里很有价值
但是当我单击复选框时,该值是错误的
我的html中有我的代码:
<input type="checkbox" [(ngModel)]=material.validated (click)="updateValidation(material)">
在我的ts:
public updateValidation(material: any) {
this.requestService.updateVersionQuotation(this.quotationId, this.versionId, this.quotation);
}
答案 0 :(得分:1)
当您监听click事件时,您不是在听输入更改,而是在之前发生的click事件。
尝试收听correct event:
<input type="checkbox" (change)="updateValidation()">
我删除了ngModel
绑定,因为您似乎在函数中不需要它,并且通常不同时使用事件和绑定来管理单个输入。
答案 1 :(得分:1)
按如下所示更改HTML
<input type="checkbox" [(ngModel)]="material.validated" (change)="updateValidation(material)">
组件为
material = {};
public updateValidation(material: any) {
this.requestService.updateVersionQuotation(this.quotationId, this.versionId, this.quotation);
}