admin管理员组文章数量:1353610
I have an ng-repeat
with a bunch of radio buttons inside:
<div class="panel panel-default" ng-repeat="offer in vm.offerList">
...
<td ng-show="offer.edit">
<div class="row">
<input type="radio" name="before" ng-model="offer.before" value="false">
<input type="radio" name="before" ng-model="offer.before" value="true">
</div>
</td>
...
</div>
The model offer.before
has the correct value, however, when the row is shown, the radio button doesn't appear checked. Why is this happening? I need the radio button to show the selected value.
This is a fiddle example of my problem: /
I have an ng-repeat
with a bunch of radio buttons inside:
<div class="panel panel-default" ng-repeat="offer in vm.offerList">
...
<td ng-show="offer.edit">
<div class="row">
<input type="radio" name="before" ng-model="offer.before" value="false">
<input type="radio" name="before" ng-model="offer.before" value="true">
</div>
</td>
...
</div>
The model offer.before
has the correct value, however, when the row is shown, the radio button doesn't appear checked. Why is this happening? I need the radio button to show the selected value.
This is a fiddle example of my problem: http://jsfiddle/danielrvt/dpoLdgjq/
Share Improve this question edited Feb 3, 2017 at 16:41 danielrvt asked Feb 3, 2017 at 16:32 danielrvtdanielrvt 10.9k21 gold badges84 silver badges129 bronze badges1 Answer
Reset to default 10Because anything inside attribute value
gets toString()
like value true
will be considered as 'true'
& it will looks for 'true'
(string) instead of true
(boolean).
Better use ng-value
instead of value
attribute. It will treat true
value as in true
of type boolean only.
Additionally in your case you have to add name
attribute to be unique for each radio button group each offer
element radio will be considered as unique form element.
Markup
<div class="row">
{{offer.before}}
<input type="radio" name="before{{$index}}" ng-model="offer.before" ng-value="false">
<input type="radio" name="before{{$index}}" ng-model="offer.before" ng-value="true">
</div>
Forked Fiddle
本文标签: javascriptAngularJSRadio button not checkedStack Overflow
版权声明:本文标题:javascript - AngularJS - Radio button not checked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743895017a2557622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论