gpt4 book ai didi

html - 表格中的复选框以选择 Angular 中的表格行

转载 作者:行者123 更新时间:2023-11-28 02:24:35 25 4
gpt4 key购买 nike

我在 Angular 6 中有一个表格,里面有一个复选框吗?我想要做的是选择表格行,即复选框,然后点击选择按钮并提交。我想知道 table 是否必须包裹在 <form> 中.到目前为止,我的 HTML 结构是,但它不起作用:

 <form [formGroup]="assetForm" (ngSubmit)="onSubmit()">
<table class="table table-striped table-hover mb-10">
<thead>
<tr>
<th>Number</th>
<th>Sev</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let incident of data">
<td>
<label class="form-radio">
<input type="radio" name="id_number" value="id_number">
<i class="form-icon"></i>{{incident.number}}
</label></td>
<td>{{incident.sev}}</td>
<td>{{incident.phone}}</td>
</tr>
</tbody>
</table>
<button class="btn btn-primary" [disabled]="!Form.valid" type="submit">Select</button>
</form>

Ts.file

onSubmit() {
if (this.assetForm.invalid) {
this.assetForm.setErrors({ ...this.assetForm.errors, 'required': true });
return;
}
this.uploading = true;
this.service.post(this.assetForm.value).subscribe((response: any) => {
console.log(response);//On success response

}, (errorResponse: any) => {
console.log(errorResponse); //On unsuccessful response
this.error = true;
this.uploading = false;
});
}

最佳答案

<tr *ngFor="let incident of data">
<td>
<label class="form-radio">
<input type="radio" name="id_number" value="id_number" [(ngModel)]="incident.checked">
<i class="form-icon"></i>{{incident.number}}
</label>
</td>
<td>{{incident.sev}}</td>
<td>{{incident.phone}}</td>
</tr>

试一试,希望它能奏效。

关于html - 表格中的复选框以选择 Angular 中的表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55159756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com