在我的Angular1.x应用程序中,我的模型正确地映射到我的无线电选择,但是除最后一个之外没有选择单选按钮本身。不确定问题是什么。我在下面创建了一个非常小的例子来说明这种行为。非常感谢任何帮助。
http://plnkr.co/edit/dgGCvtOEb9WKTNtQHjqd?p=preview
angular.module('todoApp', [])
.controller('TodoListController', function() {
var todoList = this;
todoList.questions = [{
"category": "Movies",
"questions": [{
"title": "M1",
"score": "4",
},
{
"title": "M2",
"score": "2",
}
]
},
{
"category": "Foods",
"questions": [{
"title": "F1",
"score": "3",
},
{
"title": "F2",
"score": "4",
}
]
},
{
"category": "Sports",
"questions": [{
"title": "S1",
"score": "5",
}]
}
];
});
<!doctype html>
<html ng-app="todoApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/css/bootstrap-combined.min.css">
</head>
<body>
<h2>Todo</h2>
<div ng-controller="TodoListController as todoList">
<div ng-repeat="(ccKey, cc) in todoList.questions">
<hr/>
<div>
<b style="color: red;">Category</b> : {{cc.category}}
</div>
<div ng-repeat="(qqKey, qq) in cc.questions">
<br/>
{{qq.title}} : Selected Score: {{qq.score}}
<br/>
<div ng-repeat="n in [].constructor(5) track by $index">
<input type="radio" ng-model="qq.score" name="q-{{ccKey}}-{{qqKey}}" value="{{$index+1}}"><br/>Score: {{$index+1}} : Group: q-{{ccKey}}-{{qqKey}}
</div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
尝试从Public Function CONCATENATEFORERIC(rng As Range) As String
Dim rng1 As Range
CONCATENATEFORERIC = ""
For Each rng1 In rng
CONCATENATEFORERIC = CONCATENATEFORERIC & rng1.Text
Next rng1
End Function
标记中删除name
属性。这似乎导致与Angular管理您的无线电标签的行为发生冲突。我能够看到所有类别都被选中,并且选择仍然在给定的问题中分组。
在Angular输入[radio]文档中,他们没有使用<input type="radio">
属性显示:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D
答案 1 :(得分:0)
如果您想要的是首次加载页面时的初始值选择,请使用
ng-value="($index+1).toString()"
由于您的分数是以字符串形式给出的,因此当您使用&#34; ng-value&#34;时,您需要将数字转换为字符串以匹配分数。或者更好的是,您可以将得分设置为整数,并保持其余代码不变:
todoList.questions = [{
"category": "Movies",
"questions": [{
"title": "M1",
"score": 4,
},
{
"title": "M2",
"score": 2,
}
]
}, ....