[英]Angular - using radio buttons
I believe I'm following correctly the AngularJS official documentation for radio buttons . 我相信我正确地遵循了有关单选按钮的AngularJS官方文档 。
So, I created this code: 因此,我创建了以下代码:
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>
Also, I made other attempting using ng-value, like this... 另外,我还尝试了其他使用ng-value的尝试,像这样...
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>
and this is my controller 这是我的控制器
angular
.module('app')
.controller('ModalInstanceUpgradeSolutionCtrl', function ($scope,$rootScope, $uibModalInstance, appId) {
$scope.prices = [{
months: 1, price : 20
}, { months 2: price: 40}]
});
The question is: What could be wrong ? 问题是:可能出什么问题了? because when I click on the radio buitton, this is not updating the model indexSelected.
因为当我单击单选按钮时,这不会更新型号indexSelected。 Any clue ?
有什么线索吗?
Ok, found the error. 好的,发现了错误。 @charlietfl gave me some hint.
@charlietfl给了我一些提示。 Enough to google it.
足够谷歌了。
If I replace ng-model="indexSelected" for ng-model="$parent.indexSelected", this will access the parent scope. 如果我将ng-model =“ $ SelectSelected”替换为ng-model =“ $ parent.indexSelected”,这将访问父作用域。 ng-repeat creates a child scope.
ng-repeat创建一个子范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.