admin管理员组文章数量:1302403
I have 3 radio buttons as follows:
.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>
I dont want to use [(ngModel)]
because of package issues .
I want to use [] and () traditional ways .
Now, the thing is values are not getting changed in the selectedRadioButtonValue . Whats the issue here?
export class EmployeeComponent {
selectedRadioButtonValue: string = "All";
}
I have 3 radio buttons as follows:
.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>
I dont want to use [(ngModel)]
because of package issues .
I want to use [] and () traditional ways .
Now, the thing is values are not getting changed in the selectedRadioButtonValue . Whats the issue here?
export class EmployeeComponent {
selectedRadioButtonValue: string = "All";
}
Share
edited Nov 25, 2017 at 9:27
bamtheboozle
6,4362 gold badges20 silver badges32 bronze badges
asked Nov 25, 2017 at 9:01
user1400915user1400915
1,9437 gold badges30 silver badges55 bronze badges
2 Answers
Reset to default 5For two way data binding its as same as all others use this syntax [(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>
without ngModel
Demo :
using change
event binding and the value of checked
attribute must be a boolean not a string because strings are truthy :
<input type="radio" name = "options" value="All" [checked]="selectedRadioButtonValue === 'All'" (change)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"All("+all+")"}}</span>
<input type="radio" name = "options" value="Male" [checked]="selectedRadioButtonValue === 'Male' " (change)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"Male("+male+")"}}</span>
<input type="radio" name = "options" value="Female" [checked]="selectedRadioButtonValue === 'Female'" (change)='selectedRadioButtonValue=$event.target.value' />
<span class="radioClass">{{"Female("+female+")"}}</span>
本文标签: javascriptAngular 2 Radio Button 2 way BindingStack Overflow
版权声明:本文标题:javascript - Angular 2 Radio Button 2 way Binding - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741670194a2391556.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论