在我的表单中,我使用了两个单选按钮,并希望检查选定的值。但这并不如预期的那样。我想确定各个无线电选择值,并在结果列中显示大/小ng-change事件只在ng-repeat中触发一次
<div ng-controller="CityCtrl">
<table>
<tr>
<th>Name</th>
<th>Big</th>
<th>Small</th>
<th>Result</th>
</tr>
<tr ng-repeat="city in cities">
<td>{{ city.name }}</td>
<td>
<input type="radio" name="{{city.name}}-{{$index}}" ng-model="big" value="big_value" ng-change="check(city.name, big)">
</td>
<td>
<input type="radio" name="{{city.name}}-{{$index}}" ng-model="small" value="small_value" ng-change="check(city.name, small)">
</td>
<td>***</td>
</tr>
</table>
</div>
控制器:
var myApp = angular.module('cityApp', []);
function CityCtrl($scope) {
$scope.big = '';
$scope.small = '';
$scope.cities = [{
id: 1,
name: 'Tokyo'
}, {
id: 2,
name: 'Guangzhou'
}, {
id: 3,
name: 'Seoul'
}];
$scope.check = function(city, value) {
console.log("City->" + city + " ::: Value->" + value);
};
}
从我做了推断的几件事情其他答案:
- 了解JS中的原型继承?
- NG-重复产生影响无线电
我没玩过周围NG-重复
这里是小提琴: http://jsfiddle.net/mw2us37h/
注:我没有使用NG-价值,但通过硬编码的值 。 更改为NG-点击不工作或者
[ng-change事件只能在使用ng-repeat创建时为每个单选按钮触发一次]的可能重复(http://stackoverflow.com/questions/23790239/ng-change-event-only-fires-once- for-each-radio-button-when-created-with-ng-repea) – OstrichProjects
你是否想要选择多个城市?或一个城市? –