我有 3 个单选按钮,如下所示:
.html:
<input type="radio" name = "options" value="All" [checked]='selectedRadioButtonValue' (input)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"All("+all+")"}}</span>
<input type="radio" name = "options" value="Male" [checked]='selectedRadioButtonValue' (input)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"Male("+male+")"}}</span>
<input type="radio" name = "options" value="Female" [checked]='selectedRadioButtonValue' (input)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"Female("+female+")"}}</span>
由于软件包问题,我不想使用[(ngModel)]
。
我想使用[]和()传统方式。
现在,问题是 selectedRadioButtonValue 中的值没有发生变化。这里有什么问题吗?
export class EmployeeComponent {
selectedRadioButtonValue: string = "All";
}
最佳答案
对于两种方式的数据绑定(bind),它与所有其他使用此语法的方式相同[(ngModel)]
<div class="form-group">
<label>Gender:</label>
<label class="radio-inline">
<input type="radio" name="optradio" value='Male' [(ngModel)]="employee.gender" >Male
</label>
<label class="radio-inline">
<input type="radio" name="optradio" value='Female' [(ngModel)]="employee.gender" >Female
</label>
关于javascript - Angular 2 单选按钮 2 路绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484236/