这是我写的AngularJS。我想用ng-repeat的单选按钮,但它不工作
<script type="text/javascript">
var app = angular.module("App1", []);
app.controller("ctrl1", function ($scope, $filter) {
$scope.GenderChoice = ["Male","Female"];
});
</script>
以下代码是工作。当我更改单选按钮时,“性别”更改值。
<input id="MaleOption" name="oo" type="radio" ng-model="Gender" value="{{GenderChoice[0]}}" />
<input id="FemaleOption" name="oo" type="radio" ng-model="Gender" value="{{GenderChoice[1]}}" />
我想用单选按钮使用ng-repeat。下面的代码是行不通的。当我单击更改单选按钮时,“性别”不是响应。其实,“性别”从未表现出价值。
<input ng-repeat="x in GenderChoice" id="{{x}}Option" name="oo" type="radio" ng-model="Gender" value="{{x}}" />
以下代码不工作。
<input ng-repeat="x in GenderChoice" id="{{x}}Option" name="oo" type="radio" ng-model="Gender" value="{{GenderChoice[$index]}}" />
这些代码有什么问题。感谢提前。
您plunker链接没有按没有你的代码。编辑了 – Claies
的链接,你现在可以看到正在工作的plunker – Arashk