Angular2 構文を使用して列挙型定義からラジオ ボタンを作成し、その値をその列挙型のプロパティにバインドしようとしています。
私のhtmlには次が含まれています:
<div class="from_elem">
<label>Motif</label><br>
<div *ngFor="let choice of motifChoices">
<input type="radio" name="motif" [(ngModel)]="choice.value"/>{{choice.motif}}<br>
</div>
</div>
@Component で、選択肢と値のセットを宣言しました。
private motifChoices: any[] = [];
そして、 @Component のコンストラクターで、次の方法で選択肢を埋めました。
constructor( private interService: InterventionService )
{
this.motifChoices =
Object.keys(MotifIntervention).filter( key => isNaN( Number( key )))
.map( key => { return { motif: key, value: false } });
}
ラジオ ボタンが正しく表示されるので、選択した値をプロパティにバインドしようとしています。しかし、ボタンの 1 つをクリックすると、choice.value の値が undefined に設定されます。