我正在使用Angular 2 RC7。
我的单选按钮没有绑定,但为什么?
我根本没有收到任何错误消息。
<input name="options" [value]="true" [(ngModel)]="gradingKey.halfScoresCount" type="radio" />
<input name="options" [value]="false" [(ngModel)]="gradingKey.halfScoresCount" type="radio" />
export class EditGradingKey {
halfScoresCount: string;
constructor(obj:any) {
this.halfScoresCount = "true"; //obj.halfScoresCount;
}
}
答案 0 :(得分:0)
我是这样做的,就像我发现的那样:http://plnkr.co/edit/pRPwDKP9wpp7hOlOgBbx?p=preview
<div class="form-group">
<label>Half scores count?</label>
<div style="display:inline-block;" *ngFor="let answer of gradingKey.halfScoresCountAnswers">
<label><input type="radio" name="answer" [(ngModel)]="gradingKey.currentAnswer" [value]="answer.value">{{answer.display}}</label>
</div>
</div>
export class EditGradingKey {
genders: any[];
currentAnswer: any;
constructor(obj: any) {
this.genders = [ { value: 'true', display: 'Yes I want' },{ value: 'false', display: 'No I don`t' } ];
this.currentAnswer= obj.halfScoresCount == true ? this.genders[0].value : this.genders[1].value;
}
}