我有 {{policy.isActiveInPolicyGroup}}
,它是 bool 值,我想检查 radio 输入是否为真。
<div ng-repeat="policy in item.policies">
<input type="radio" ng-model="item.selectedPolicy" id="policy_{{$index}}"
name="test" ng-value="policy.id">
<label class="custom-control-label" for="test">
{{item.name}}
</label>
</div>
最佳答案
首先你应该知道它是关于 radio 类型的输入值:
推荐
the radio inputs can't define by Boolean, if inputs are more than 2 we can't define value as Boolean so we should set a different value for each of them.
Ex:
<input type="radio" name="test" ng-value="1">
,<input type="radio" name="test" ng-value="2">
,<input type="radio" name="test" ng-value="3">
不推荐
Note: Except when input number is 2: in this case we can set value
false
ortrue
Ex:
<input type="radio" name="test" ng-value="true">
,<input type="radio" name="test" ng-value="false">
radio 输入注:
all radio inputs in one group should have same name
复选框输入:
inputs with checkbox type by default define with Boolean value because we can set different name for each of them, and result is checked [true] or not [false]
ng-模型和 ng-值
radio 输入应该有两个属性ng-model
和 ng-value
那是因为在 angularjs 逻辑中 ng-model
应该等于 ng-value
并且不能通过一个属性来完成。
关于html - 当我已经在使用 ng-model 和 ng-value 时,我想用后面的数据检查我的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57302965/