1

我是 angularjs 的新手,并试图找到将无线电组的选定值设置为 ngmodel 的解决方案。

//my.html     

<div ng-controller='controller'> 
 <div class="btn-group" ng-model="option" ng-repeat="arr in dragDropOption">
  <input type="radio" name="optionCorrectOpt" data-ng-model="option" 
    value="{{dragDropOption[$index].text}}">
      {{dragDropOption[$index].text}}
</div>

和 //mycontroller.js

 app = angular.module('app', []);

 app.controller('controller', function ($scope) {
 $scope.dragDropOption = [];
 $scope.option = "not set";

 $scope.dragDropOption = [{
     text: "analog"
 }, {
     text: "isdn"
 }, {
     text: "dsl"
 }];
 //   $scope.option = $scope.dragDropOption[0].text;
});

我的小提琴在这里

可能是重复的问题,请帮助我分享已经回答的 stackoverflow 问题的链接或新答案。提前致谢。

4

2 回答 2

2

代替

$scope.option = "not set";

<input type="radio" name="optionCorrectOpt" data-ng-model="option" 
value="{{dragDropOption[$index].text}}">

到:

 $scope.radioOption = {};
 $scope.radioOption.selected = "not set"

 <input type="radio" name="optionCorrectOpt" data-ng-model="radioOption.selected" 
value="{{dragDropOption[$index].text}}">

JS小提琴

于 2014-04-01T11:41:16.113 回答
2

为了input改变

data-ng-model="option"

到:

data-ng-model="$parent.option"

演示Fiddle

于 2014-04-01T11:43:09.787 回答