[英]Radio group selected option not updating ngModel value in angular
我是angularjs的新手,正在嘗試找到將radio group的選定值設置為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問題的鏈接或新答案。 提前致謝。
更換
$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}}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.