양식 내에서 라디오 버튼 목록을 사용하는 데 문제가 있습니다. 내 코드 아래.
보기각도 - 라디오 버튼 목록이 작동하지 않습니다.
<form novalidate (ngSubmit)="onSubmit()" [formGroup]="perito">
<div class="form-group row">
<table class="table">
<thead></thead>
<tbody>
<tr *ngFor="let p of periti">
<td>{{p.nome}} {{p.cognome}}</td>
<td>{{p.indirizzo}} {{p.civico}} - {{p.cap}}
{{p.comune}}
</td>
<td><input formControlName="idPerito" type="radio" [value]="p.id" (change)="onSelect(p.id)"></td>
</tr>
</tbody>
</table>
</div>
</form>
컨트롤러
perito: FormGroup;
ngOnInit() {
this.perito = new FormGroup({
idPerito: new FormControl()
});
}
onSelect() {
console.log(this.perito.value);
}
문제는 내가 한 라디오 버튼을 선택할 때이다 :
- 다른 모든 라디오 버튼
- 너무 선택하세요 형태 o 개체가 정의되지 않았습니다.
라디오 버튼 목록을 관리하는 올바른 방법은 무엇입니까? 감사. 그들은 기본 키 때문에
this.peritiSrv.getPeriti()
.then(res => {
this.periti = res;
})
.catch();
어쨌든,이 두 periti
개체에 대한 동일한 ID를 가지고 일 할 수 없습니다 -
편집이 내 periti
배열을 채우는 방법이다.
퍼티 배열을 제공 할 수 있습니까? 같은 어딘가에있을 수도 있습니다. 왜냐하면 라디오 버튼에 대한 값이 동일 할 때 이런 일이 발생할 수 있기 때문입니다. – lingthe
내 편집 감사를 참조하십시오. – esseara
나는 그 배열의 예를 보여 주려고했다. – lingthe