Javascript 将ng repeat中的单选按钮设置为checked

Javascript 将ng repeat中的单选按钮设置为checked,javascript,angularjs,Javascript,Angularjs,晚上好。有人能告诉我如何设置单选按钮以在加载ng repeat时签入吗?在下表中,我创建了一个带有排序功能的价格列表。它从最低价到最低价排序。是否有一种方法可以在每次加载表格时将最低价格单选按钮设置为“选中” <table> <tr ng-repeat="prices in productVariant.prices | orderBy: tcoSort"> <td><strong>{{prices.code }}</strong&

晚上好。有人能告诉我如何设置单选按钮以在加载ng repeat时签入吗?在下表中,我创建了一个带有排序功能的价格列表。它从最低价到最低价排序。是否有一种方法可以在每次加载表格时将最低价格单选按钮设置为“选中”

<table> 
<tr ng-repeat="prices in productVariant.prices | orderBy: tcoSort">
    <td><strong>{{prices.code }}</strong></td>
    <td ng-click="displayFullPricing(prices)">
            <input type="radio"  name="{{variant.code}}" ng-click="displayFullPricing(prices, $index)">
        </td>
</tr>
谢谢



非常简单,使用$scope.modelName并将其值设置为默认情况下要设置的单选按钮的任何值(属性),例如:-

 <div ng-repeat="check in people">
                <input type="radio" name="hello" value="{{check.name}}" ng-model="$parent.human"/> {{check.name}}
                </div>

 $scope.people=[
        { 
            'name':'rachit'
        },
        { 
            'name':'gulati'
        },
        { 
            'name':'rocks'
        }
    ]
    $scope.human='gulati';//You need to set it to the lowest price from your array .
男性 女性

现在在控制器中设置$scope.one=“male”,您将获得单选按钮的默认值

在ng repeat的情况下,概念是相同的,但您只需要在ng repeat的模型中使用$parent,因为ng repeat创建了自己的作用域,无法从控制器访问

下面是一个小的模拟示例:-

 <div ng-repeat="check in people">
                <input type="radio" name="hello" value="{{check.name}}" ng-model="$parent.human"/> {{check.name}}
                </div>

 $scope.people=[
        { 
            'name':'rachit'
        },
        { 
            'name':'gulati'
        },
        { 
            'name':'rocks'
        }
    ]
    $scope.human='gulati';//You need to set it to the lowest price from your array .

{{check.name}
$scope.people=[
{ 
“姓名”:“拉希特”
},
{ 
“姓名”:“古拉蒂”
},
{ 
“名称”:“岩石”
}
]
$scope.human='gulati'//您需要将其设置为阵列中的最低价格。

下面是一个使用复选框的示例,您可以使用:

<tr ng-repeat="content in contents" ng-class="{danger: currentContent.resource_uri === content.resource_uri || checkboxes.isSelected[content.id]}"  name="content[{{$index}}]" ng-click="selectContent(content, $index);">
      <td class="grid-checkbox"><input type="checkbox" ng-model="checkboxes.isSelected[content.id]" name="checkbox[{{content.id}}]" ng-checked="checkboxes.isSelected[content.id]" ng-change="changeCheckbox(content, $index)"/></td></tr>

这是我的代码片段我想你需要的是

<input type="checkbox" ng-model="checkboxes.isSelected[content.id]" name="checkbox[{{content.id}}]" ng-checked="checkboxes.isSelected[content.id]" ng-change="changeCheckbox(content, $index)"/>


希望能有所帮助

啊,我明白了。。。没有真正理解ng repeat指令,我明白了为什么现在不行了……啊,我明白了,我错过了ng模型
<input type="checkbox" ng-model="checkboxes.isSelected[content.id]" name="checkbox[{{content.id}}]" ng-checked="checkboxes.isSelected[content.id]" ng-change="changeCheckbox(content, $index)"/>