启用单选按钮在页面上加载angularjs

时间:2017-02-08 11:31:36

标签: html angularjs

<div class="form-group" style="margin-top: 20px;" ng-repeat="row in skuDetails">
  <label class="checkbox-inline">
    <input type="radio" name="amount_{{$index}}" value="amount" ng-model="row.amount" ng-checked="row.reductionAmount != '' ">Reduction Amount
  </label>
  <label class="checkbox-inline" style="padding-left: 0px;">
    <input type="text" name="reductiontext" value="" ng-model="row.reductionAmount" style="width: 80px;">
  </label>
  <label class="checkbox-inline" style="padding-left: 0px;">
    <input type="radio" name="percentage_{{$index}}" value="percentage" ng-model="row.amount">Reduction Percentage
  </label>
  <label class="checkbox-inline" style="padding-left: 0px;">
    <input type="text" name="reductiontext" value="" ng-model="row.reductionPercentage" style="width: 80px;">
  </label>
</div>

控制器:

dao.getPromotion(scope.sesssionMessageObject.promotionId).then(function(response) {
  scope.responseObject = response.data.data;
  console.log(scope.responseObject);
  scope.skuDetails = scope.responseObject.skus;
});

嗨。我在启用页面上的单选按钮时出现问题Load.Problem是,当我的页面被加载时,从控制器调用api并且数据存储在skuDetails中(包含name,mrp reductionAmount等)。在视图中,如果reduAmount(整数)包含值,我将遍历skuDetails并启用单选按钮Reductionamount。 getPromotion调用api并检索details.But not working!

3 个答案:

答案 0 :(得分:1)

试试这个,

<input ng-init="(!!row.reductionAmount)?row.amount = row.reductionAmount:''" type="radio" name="amount_{{$index}}" value="{{row.reductionAmount}}" ng-model="row.amount">Reduction Amount

仅当ng-model中的value和值相同时,才会选中复选框。

所以我们这样做,

row.reductionAmount -------> value attribute
row.reductionAmount -------> row.amount (only when row.reductionAmount is not null)

我们将row.reductionAmount分配给row.amount并将value属性设置为row.reductionAmount

答案 1 :(得分:1)

您应该使用C3P0代替ng-value并删除ng-checked属性,我认为这是没有意义的。

value

答案 2 :(得分:0)

您可以使用ng-init,如下所示

<div ng-repeat="row in skuDetails" 
     ng-init="row.amount = row.reductionAmount != '' ? true : false">

并删除此ng-value="row.reductionAmount != ''我认为这没有任何意义