[英]AngularJS - Radio button not checked
I have an ng-repeat
with a bunch of radio buttons inside: 我有一个带有一堆单选按钮的
ng-repeat
:
<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. 模型
offer.before
具有正确的值,但是,当显示该行时,单选按钮不会显示为已选中。 Why is this happening? 为什么会这样? I need the radio button to show the selected value.
我需要单选按钮来显示所选值。
This is a fiddle example of my problem: http://jsfiddle.net/danielrvt/dpoLdgjq/ 这是我的问题的一个小例子: http : //jsfiddle.net/danielrvt/dpoLdgjq/
Because anything inside attribute value
gets toString()
like value true
will be considered as 'true'
& it will looks for 'true'
(string) instead of true
(boolean). 因为属性
value
内的任何东西都得到toString()
因为值true
将被视为'true'
并且它将查找'true'
(字符串)而不是true
(布尔值)。
Better use ng-value
instead of value
attribute. 更好地使用
ng-value
而不是value
属性。 It will treat true
value as in true
of type boolean only. 它会将
true
值视为类型为boolean的true
。
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. 此外,在你的情况,你必须添加
name
属性是每个单选按钮组的每个唯一offer
元素电台将被视为独特的表单元素。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.