0
我相信我正确遵循AngularJS official documentation for radio buttons。Angular - 使用单选按钮
所以,我创造了这个代码:
indexSelected={{indexSelected}}
<form name="form">
<div class="form-group">
<label ng-repeat="s in prices track by $index" style="width: 100%">
<input type="radio" name ="option" ng-model="indexSelected" value="{{s.months}}"> {{s.price}} + vat
</label>
</div>
</form>
而且,我做其他的尝试使用NG-值,像这样...
indexSelected={{indexSelected}}
<form name="form">
<div class="form-group">
<label ng-repeat="s in prices track by $index" style="width: 100%">
<input type="radio" name ="option" ng-model="indexSelected" ng-value="s.months"> {{s.price}} + vat
</label>
</div>
</form>
,这是我的控制器
angular
.module('app')
.controller('ModalInstanceUpgradeSolutionCtrl', function ($scope,$rootScope, $uibModalInstance, appId) {
$scope.prices = [{
months: 1, price : 20
}, { months 2: price: 40}]
});
问题是:什么可能是错的?因为当我点击广播buitton时,这不会更新模型indexSelected。任何线索?
你打破了在ng模型中不使用对象的黄金法则,因此会由于ng-repeat而陷入子范围问题 – charlietfl