admin管理员组文章数量:1435822
I've got small problem with ng-repeat on persons with multiple radio inputs (yes/no). Input names should be different because of name="person.name" but it behaves like they all are the same. Somebody knows how to fix this?
/
HTML:
<form name="myForm" ng-controller="MyCtrl">
<p>Decisions</p>
<ul>
<li ng-repeat="person in people">
<label>{{person.name}}
<input type="radio" ng-model="person.decision" name="person.name" value="Yes" />
<input type="radio" ng-model="person.decision" name="person.name" value="No" />
</label>
</li>
</ul>
</form>
JS:
function MyCtrl($scope) {
$scope.people = [{
name: "John"
}, {
name: "Paul"
}, {
name: "George"
}, {
name: "Ringo"
}];
}
I've got small problem with ng-repeat on persons with multiple radio inputs (yes/no). Input names should be different because of name="person.name" but it behaves like they all are the same. Somebody knows how to fix this?
http://jsfiddle/Chotkos/EbU8g/
HTML:
<form name="myForm" ng-controller="MyCtrl">
<p>Decisions</p>
<ul>
<li ng-repeat="person in people">
<label>{{person.name}}
<input type="radio" ng-model="person.decision" name="person.name" value="Yes" />
<input type="radio" ng-model="person.decision" name="person.name" value="No" />
</label>
</li>
</ul>
</form>
JS:
function MyCtrl($scope) {
$scope.people = [{
name: "John"
}, {
name: "Paul"
}, {
name: "George"
}, {
name: "Ringo"
}];
}
Share
Improve this question
edited Jul 1, 2022 at 20:09
Jonas
129k103 gold badges328 silver badges405 bronze badges
asked Jul 15, 2014 at 16:05
chotkoschotkos
1801 silver badge10 bronze badges
1
- For more information about when to use curly braces in angular, refer to stackoverflow./questions/17878560/… – Jorge Zuverza Commented Jul 15, 2014 at 16:20
3 Answers
Reset to default 6You need to use {{ person.name }}
, rather than "person.name"
in that context.
I don't know why you got downvoted. Your question was fine. So you are using the name
property which is traditional in an HTML form. Since name
isn't part of angular, you need to wrap the person.name
in curly brackets name="{{person.name}}"
so angular knows to parse it.
Please see here: http://jsfiddle/Chotkos/EbU8g/ that happend because you wrapped all inputs into label tag
<form name="myForm" ng-controller="MyCtrl">
<p>Decisions</p>
<ul>
<li ng-repeat="person in people">
<label>{{person.name}}</label>
<input type="radio" ng-model="person.decision" name="person.name" value="Yes" />
<input type="radio" ng-model="person.decision" name="person.name" value="No" />
</li>
</ul>
</form>
本文标签: javascriptAngularJS ngrepeat with multiple radio inputsStack Overflow
版权声明:本文标题:javascript - AngularJS ng-repeat with multiple radio inputs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745640636a2667834.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论