Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 单击保存按钮时,单选按钮模型返回未定义的值_Html_Angularjs_Radio Button_Angularjs Ng Model - Fatal编程技术网

Html 单击保存按钮时,单选按钮模型返回未定义的值

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

我有两个单选按钮,我分别为其赋值为“0”和“1”。我需要在单击“保存”按钮时获取该值,但它返回一个未定义的值。这是我的密码。我有什么问题

<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每条记录中定义单选对象。我已根据您的要求更新了答案。