我尝试了很多选项来根据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>


帮助我找出是否存在其他替代方法?

最佳答案

您是否尝试过使用angular的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">

07-28 03:10