【发布时间】:2014-07-12 22:08:36
【问题描述】:
我遇到了角度问题,但我不明白问题可能是什么:
这是一个 div:
<div ng-controller="CountrySelectorController">
Selected Countryid = {{countryid}}
<div class="radio" ng-repeat="country in countries">
<input type="radio" name="countryOptions" ng-model="countryid" value={{country.countryid}} ng-checked="countryid == country.countryid" /><span style="margin-left:10px;">{{country.countryid}}.{{country.name}}</span>
</label>
</div>
</div>
那是我的控制器:
app.controller('CountrySelectorController', function($scope, $rootScope){
$scope.countryid = 1;
});
我遇到的问题: -Selected Countryid=1 出现在 start 。虽然我选择了不同的国家,但是模型没有更新
【问题讨论】:
-
你不应该使用 ng-checked。
-
@dotnetstep,我用了checked,没问题,但是model不是udpdating,Selected Countryid总是1
-
@Braulio,我就是这样做的,使用具有相同型号、相同名称和不同值的单选按钮
-
抱歉,Jerrad 是对的,避免 $parent 内容的另一种方法是将范围可见数据包装在“模型”中,例如 $scope.model.countryid,然后在您的 ng -model 你会使用类似 ng-model="model.countryid"
标签: angularjs