ng-checked在应用程序中不起作用,因为它的复选框没有任何效果,我面临单选按钮的问题
<input type="radio" class="radio" name="job_class_radio" ng-checked="key===jobClassData.selectedOption" ng-click=changeJobClass(value)>
我在浏览器检查元素中看到了这个
<input type="radio" class="radio" name="job_class_radio" ng-checked="key===jobClassData.selectedOption" ng-click="changeJobClass(value)" checked="checked">
我们可以看到 checked =“checked”在编译后添加
更新
<label class="radio" ng-if="key!='selectedOption'" ng-repeat="(key,value) in jobClassData track by $index">
<input type="radio" class="radio" name="job_class_radio" ng-checked="jobClassData.selectedOption===key" ng-value="key" ng-click=changeJobClass(value)>
<span class="radio"></span>
<span ng-bind="key"></span>
</label>
JSON:
{
"selectedOption": "Unit Category",
"Job Class": [
{},
{}
],
"Unit Category": [
{},
{},
{}
]
}
我想根据 selectedOption 键
选择属性答案 0 :(得分:-1)
如果您想要单选按钮进行默认选项,则应该具有&#39;值&#39;和&#39; ng-model&#39;属性。
<input type="radio" class="radio" name="job_class_radio" ng-model="jobClassData.selectedOption" value="option1">
在控制器中:
$scope.jobClassData = {
selectedOption: 'option1'
}
您可以在此处详细了解:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D