我使用Angular JS从数据库中检索行,并将数据放入一个可编辑的表单中;该表单由多个单选按钮组成。我希望确保何时检索数据;根据$scope.radio_val中给出的值选择特定的单选按钮
<td>
<input type="radio" ng-model="tube" class="form-check-input ml-5"
name="optradio" value="Grey">
<i class="fas fa-vial" style="color:#757575;font-size: 24px;"></i>
<span class="ml-4">Grey</span>
</td>
<td>
<input type="radio" ng-model="tube" class="form-check-input ml-5"
name="optradio" value="Black">
<i class="fas fa-vial" style="color:#212121;font-size: 24px;"></i>
<span class="ml-4">Black</span>
</td>
<td>
<input type="radio" ng-model="tube" class="form-check-input ml-5"
name="optradio" value="Culture">
<i class="fas fa-vial" style="color:#EEFF41;font-size: 24px;"></i>
<span class="ml-4">Culture</span>
</td>
<td>
<input type="radio" ng-model="tube" class="form-check-input ml-5"
name="optradio" value="Urine">
<i class="fas fa-prescription-bottle" style="color:#C6FF00;font-size: 24px;"></i>
<span class="ml-4">Urine</span>
</td>上面的代码包含了编辑表单页面中单选按钮的一部分。
$scope.t_color=data.tube;
$('input:radio[name="optradio"][value=" $scope.t_color"]').attr('checked', true);这就是我正在尝试做的事情,但是AngularJS不工作
发布于 2019-09-29 00:29:23
不需要使用JQuery来检查单选按钮。
只需使用该值设置ng-model,具有该值的单选按钮将被选中:
$scope.tube = data.tube;发布于 2019-09-29 14:23:42
这非常简单。你可以对单选按钮进行双向绑定,因为你已经在使用ng-model了。
在你的控制器代码中,你应该这样做:
$scope.tube = data.tube;而您的HTML将保持原样。你可以参考下面的官方Angular文档链接来获得更多的理解:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D
https://stackoverflow.com/questions/58148182
复制相似问题