如何将$ scope.value名称放入$('input:radio [name =“ optradio”] [value =“ $ scope.t_color”]').attr('checked',true)

问题描述 投票:0回答:2

我正在使用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无法正常工作

jquery angularjs angularjs-scope
2个回答
0
投票
仅将ng-model设置为该值,将选择具有该值的单选按钮:

$scope.tube = data.tube;


0
投票
在控制器代码中,您应该这样做:

$scope.tube = data.tube;

您的HTML将保持原样。您可以参考下面的官方Angular文档链接以了解更多信息:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D

© www.soinside.com 2019 - 2024. All rights reserved.