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