Html 单击保存按钮时,单选按钮模型返回未定义的值
我有两个单选按钮,我分别为其赋值为“0”和“1”。我需要在单击“保存”按钮时获取该值,但它返回一个未定义的值。这是我的密码。我有什么问题Html 单击保存按钮时,单选按钮模型返回未定义的值,html,angularjs,radio-button,angularjs-ng-model,Html,Angularjs,Radio Button,Angularjs Ng Model,我有两个单选按钮,我分别为其赋值为“0”和“1”。我需要在单击“保存”按钮时获取该值,但它返回一个未定义的值。这是我的密码。我有什么问题 <tr ng-repeat="item in recruleData"> <td> {{item.package_name}} </td> <td> <input type="radio" name="radio" ng-model="radio.selecte
<tr ng-repeat="item in recruleData">
<td>
{{item.package_name}}
</td>
<td>
<input type="radio" name="radio" ng-model="radio.selectedProductBlock"
value="0" >A<br/>
<input type="radio" name="radio" ng-model="radio.selectedProductBlock"
value="1" > B
</td>
<a class="btn btn-primary pull-right" ng-click="radioValue();">Save</a>
</tr>
根据您的需求,您需要在recruleData中定义radio对象 每条记录 例: 和辐射值函数
$scope.radioValue= function(item){
alert(item.radio.selectedProductBlock);
}
$scope.radioValue = function(){
console.log($scope.radio.selectedProductBlock);
}
此外,您需要为每行单选按钮组指定一个唯一的名称。您只需在单选按钮名称中添加$index即可
HTML代码
<table>
<tr>
<th>Package</th>
<th>Actioins</th>
<th></th>
</tr>
<tr ng-repeat="item in recruleData">
<td>
{{item.package_name}}
</td>
<td>
<input type="radio" name="radio_{{$index}}" ng-model="item.radio.selectedProductBlock"
value="0" >A<br/>
<input type="radio" name="radio_{{$index}}" ng-model="item.radio.selectedProductBlock"
value="1" > B
</td>
<td><a class="btn btn-primary pull-right" ng-click="radioValue(item);">Save</a></td>
</tr>
</table>
工作您需要在对象无线电中定义布尔类型的变量
$scope.radio = {};
$scope.radio.selectedProductBlock = false;
然后
和辐射值函数
$scope.radioValue= function(item){
alert(item.radio.selectedProductBlock);
}
$scope.radioValue = function(){
console.log($scope.radio.selectedProductBlock);
}
您需要首先定义无线电变量。我这样做了,值返回ok。现在的问题是,我的单选按钮处于ng重复状态,选中的显示不正常。我选中了下部单选按钮,但下部单选按钮位于上部已选中您可能需要为每个单选按钮使用ng值我已使用ng值,但我的UI中所选的显示似乎有点混乱,点击选择其他单选按钮你需要显示你的js代码我这样做了,值返回ok现在的问题是我的单选按钮处于ng重复状态,选中的显示不正常。我检查了下部单选按钮,但下部单选按钮在上部集合上已检查如果这是在ng repeat中,您需要在ng repeat中使用的每个对象中都有变量,我如何才能做到这一点?ypu可以帮助我吗?我做了,值返回ok。现在的问题是我的单选按钮处于ng重复状态,选中的显示不正常。我选中了下部单选按钮,但上部集合上的下部单选按钮已被选中。如果希望每行都有单独的单选按钮和值,则需要在recruleData每条记录中定义单选对象。我已根据您的要求更新了答案。