我尝试了很多选项来根据angularjs值自动检查单选按钮
我已分配$scope.loyaltyType = "points";
这是我的HTML代码
<div class="radio-option-select">
<div>
<span>
<input type="radio" name="loyaltyType" id="ex1" ${loyaltyType=='punchcard'?'checked':'checked'}>
<label for="ex1">Punch Card </label>
</span>
<span>
<input type="radio" name="loyaltyType" id="ex2" ${loyaltyType=='points'?'checked':'checked'}>
<label for="ex2">Points</label>
</span>
<span>
<input type="radio" name="loyaltyType" id="ex3" ${loyaltyType=='percentage'?'checked':'checked'}>
<label for="ex3">% Of Purchase Reward Voucher</label>
</span>
</div>
</div>
帮助我找出是否存在其他替代方式?
答案 0 :(得分:0)
您是否尝试使用角度的ng-model指令?
这样的事情:
$scope.loyaltyType = "punchcard"
<input type="radio" value="punchcard" ng-model="loyaltyType">
<input type="radio" value="points" ng-model="loyaltyType">
<input type="radio" value="percentage" ng-model="loyaltyType">
答案 1 :(得分:0)
输入的值由ng-model
和ng-checked
指令
所以,那样:
<div class="radio-option-select">
<div>
<span>
<input type="radio" ng-model="loyaltyType.punchcard" ng-checked="loyaltyType.punchcard">
<label for="ex1">Punch Card </label>
</span>
<span>
<input type="radio" ng-model="loyaltyType.points" ng-checked="loyaltyType.points">
<label for="ex2">Points</label>
</span>
<span>
<input type="radio" ng-model="loyaltyType.percentage" ng-checked="loyaltyType.percentage">
<label for="ex3">% Of Purchase Reward Voucher</label>
</span>
</div>
</div>
在控制器中,设置值:
$scope.loyaltyType = {};
$scope.loyaltyType.points = true;
试试JSFiddle