Angular,ng-repeat创建多组单选按钮

时间:2016-09-30 17:08:51

标签: javascript angularjs radio-button angularjs-ng-repeat

我正在尝试使用ng-repeat创建多个集合无线电输入选项,但是,似乎在创建元素时,它们没有被赋予我想要的唯一ID("id":"1", "id":"2" or "id":"3")而是它们都得到具体命名为'fee[{{ record.id }}]',这导致最终的无线电设备只有一个支票。我在这里缺少什么?

HTML:

<div ng-app="app" ng-controller="fee_control">
  <div ng-repeat="record in fees" >
    {{ record.description }} : 
    <input type="text" value="{{ record.amount }}">
    Active: 
    <input type="radio" name="fee[{{ record.id }}]" value="{{ record.amount }}" checked />
    Inactive: 
    <input type="radio" name="fee[{{ record.id }}]" value="0" />
  </div>
</div>

使用Javascript:

    var app = angular.module('app', []);
    app.controller('fee_control', function($scope) {
    $scope.fees = [
                    {"id":"1","amount":"5.00","description":"Approved"},
                    {"id":"2","amount":"2.00","description":"Authorized"},
                    {"id":"3","amount":"2.00","description":"Settled"}
                  ];
    });

1 个答案:

答案 0 :(得分:1)

试试这个

 <div ng-repeat="record in fees" >
   {{ record.description }} : 
   <input type="text" value="{{ record.amount }}">
   Active: 
   <input type="radio" name="fee[{{ record.id }}]" value="{{record.amount }}" ng-checked="true" />
   Inactive: 
   <input type="radio" name="fee[{{ record.id }}]" value="0" />
</div>

使用ng-checked代替check :)谢谢