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;
});

私のフィドルはここにあります

質問が繰り返されている可能性があります。すでに回答済みのスタックオーバーフローの質問のリンクまたは新しい回答を共有してください。前もって感謝します。

4

2 に答える 2

2

input変更の場合

data-ng-model="option"

に:

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

デモFiddle

于 2014-04-01T11:43:09.787 に答える
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 に答える