单选按钮未按值选中 我从数据库中得到了姓氏,但是当我尝试用单选按钮绑定性别时,它显示为未显示
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !firstname.valid }">
<label for="lastname">Last Name</label>
<input type="text" class="form-control" name="last_name" [(ngModel)]="employee.last_name" #lastname="ngModel" required />
<div *ngIf="f.submitted && !firstname.valid" class="help-block">Last Name is required</div>
</div>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !gender.valid }">
<label for="lastname">Gender</label>
<label class="radio-inline">
<input type="radio" name="optradio" [value]="Male" [ngModel]="{checked: employee.gender == 'Male'}">Male
</label>
<label class="radio-inline">
<input type="radio" name="optradio">Female
</label>
</div>
答案 0 :(得分:1)
这个应该有效!
<input type="radio" [(ngModel)]="employee.gender" name="sex" value="Male">Male> </input>
答案 1 :(得分:1)
使用[value]代替值
<input type="radio" [(ngModel)]="employee.gender" name="sex" [value]="Male">Male </input>
答案 2 :(得分:1)
<label class="radio-inline">
<input type="radio" name="optradio" [checked]="employee.gender == 'Male'">Male
</label>
<label class="radio-inline">
<input type="radio" name="optradio" [checked]="employee.gender == 'Female'">Female
</label>