我正在使用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无法正常工作
ng-model
设置为该值,将选择具有该值的单选按钮:$scope.tube = data.tube;
$scope.tube = data.tube;
您的HTML将保持原样。您可以参考下面的官方Angular文档链接以了解更多信息:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D