这是代码。
list.component.html
<form nz-form [formGroup]="taskFormGroup" (submit)="saveFormData()">
<div nz-row *ngFor="let remark of checklist">
<div nz-col nzXXl="12" *ngFor="let task of remark.tasks" style="padding: .5rem;">
<div nz-row nzGutter="6" nzType="flex" nzAlign="middle" style="border-left: 5px solid rgba(167, 0, 51, 0.5);">
<div nz-col nzSpan="8">
<label [textContent]="task.name"></label>
</div>
<div nz-col nzSpan="8">
<nz-form-item>
<nz-form-control>
<nz-radio-group formControlName="radiostatus" [(ngModel)]="radio" (ngModelChange)="onChangeStatus($event)">
<label nz-radio nzValue="passed">Passed</label>
<label nz-radio nzValue="failed">Failed</label>
</nz-radio-group>
</nz-form-control>
</nz-form-item>
</div>
</div>
</div>
</div>
</form>
list.component.ts
checklist = [
{
"id": "txv3vvBr8KYB",
"assetType": {
"id": "1fKBO4w0XHg7H",
"code": "PRD",
"name": "Printing1"
},
"tasks": [
{
"id": "1fKBO4w0XHg7H",
"name": "Task 1",
"description": "Check oil spill"
},
{
"id": "ESOSA6aCrOER",
"name": "Sample1",
"description": "Desc1"
}
]
},
{
"id": "EwQciw9whx6B",
"tasks": [
{
"id": "1nU7uASqfvLPD",
"name": "TASK8888",
"description": "DESC8888"
},
{
"id": "EwQciw9whx6B",
"name": "TASK9999",
"description": "DESC9999"
}
]
}
];
当选择通过或失败时,如果选择第一个项目,则不应影响第二个项目。例如,在第一个项目上,它选择了第二个项目中的传递,而不应该选择在第二个项目上的传递。
在我选择第一项合格的时候,它会影响第二项,它也选择了合格。
答案 0 :(得分:1)
在您的代码中,所有表单控件都具有相同的ngModel绑定对象。尝试分配唯一的名称
component.html
<div nz-row *ngFor="let remark of checklist; let i = index">
<div nz-col nzXXl="12" *ngFor="let task of remark.tasks" style="padding: .5rem;">
<div nz-row nzGutter="6" nzType="flex" nzAlign="middle" style="border-left: 5px solid rgba(167, 0, 51, 0.5);">
<div nz-col nzSpan="8">
<label [textContent]="task.name"></label>
</div>
<div nz-col nzSpan="8">
<nz-form-item>
<nz-form-control>
<nz-radio-group [(ngModel)]="task.id" (ngModelChange)="onChangeStatus($event)">
<label nz-radio nzValue="passed">Passed</label>
<label nz-radio nzValue="failed">Failed</label>
</nz-radio-group>
</nz-form-control>
</nz-form-item>
</div>
</div>
</div>
</div>