[英]Radio group in ng-repeat not working as expected
A simple star rating required for each repeated item. 每个重复的项目都需要一个简单的星级。 But It's not giving the results as expected.
但是它没有给出预期的结果。
Every item's star rating changes or affects the first row. 每个项目的星级都会更改或影响第一行。
I have changed the name
attribute of my input type to add -{{$index}}
but still can't make it work. 我已将输入类型的
name
属性更改为添加-{{$index}}
但仍然无法使其正常工作。
My html 我的HTML
<div ng-repeat="item in $ctrl.serviceList | filter: $ctrl.form.searchKey" class="c-list">
<md-card>
<div class="group full-width pad15">
<div><strong>Summary:</strong>{{item.problemSummary}}</div>
<div style=" word-wrap: break-word">
<strong>Description:</strong>
<span>{{item.serviceDescription}}</span>
</div>
<div>
<strong>Docket Id: </strong>
<span>{{item.docketId}}</span>
</div>
<div><strong>Transaction Id: </strong>{{item.tid}}</div>
<div><strong>Created At: </strong>{{item.createdAt | date: 'medium'}}</div>
<div><strong>Created By: </strong>{{item.userName}}</div>
<div><strong>Status: </strong><span class="status-text-complete">{{item.status}}</span></div>
<div style="border-top: 1px solid #ccc;">
<div class="stars">
<form>
<input class="star star-5" id="star-5" type="radio" name="star-{{$index}}" value="1" ng-model="item.rating" />
<label class="star star-5" for="star-5"></label>
<input value="2" class="star star-4" id="star-4" type="radio" name="star-{{$index}}" ng-model="item.rating"/>
<label class="star star-4" for="star-4"></label>
<input value="3" class="star star-3" id="star-3" type="radio" name="star-{{$index}}" ng-model="item.rating"/>
<label class="star star-3" for="star-3"></label>
<input value="4" class="star star-2" id="star-2" type="radio" name="star-{{$index}}" ng-model="item.rating"/>
<label class="star star-2" for="star-2"></label>
<input value="5" class="star star-1" id="star-1" type="radio" name="star-{{$index}}" ng-model="item.rating"/>
<label class="star star-1" for="star-1"></label>
</form>
</div>
</div>
</div>
</md-card>
</div>
UPDATE 更新
ctrl.serviceList = response.results;
var response = {"results":[{"_id":"587f15ba2aaf761914c89498","createdAt":"2017-01-18T07:14:02.733Z","docketId":"MPA001218012017124402","mId":"5869efdd160812d78923ed9c","mobile":"9999999999","name":"new user","problemSummary":"Training Required","serviceComments":"asfsfsf","serviceDescription":"Training Required for this POS","serviceRating":3,"serviceSubType":"Re-training request","serviceType":"Training required","source":"MPA","status":"Complete","tid":"7895451455","userName":"dummy@nseit.com","__v":0},{"_id":"5880b48d85cce60d684abc98","createdAt":"2017-01-19T12:43:57.200Z","docketId":"MPA001219012017181357","mId":"5869efdd160812d78923ed9c","mobile":"9999999999","name":"new user","problemSummary":"g67675676","serviceComments":"ghgjghjhjthjhjthjhyjhjhjhh","serviceDescription":"hyjtyj","serviceRating":2,"serviceSubType":"Re-training request","serviceType":"Training required","source":"MPA","status":"Complete","tid":"7895451456","userName":"dummy@nseit.com","__v":0}],"start":0,"end":2,"total":2,"isLastPage":true,"isFirstPage":true}
I've just write some code here using your question and it seems that you need to change value attribute to ng-value attribute in your radio elements. 我只是写一些代码在这里用你的问题,看来你需要改变价值属性NG-value属性在您的无线电元件。 ng-value will change the property in your item.
ng-value将更改您商品的属性。
<input ng-value="3" class="star star-3" id="star-3" type="radio" name="star-{{$index}}" ng-model="item.rating"/>
Here my jsfiddle: http://jsfiddle.net/y6sc0g4k/2/ 这是我的jsfiddle: http : //jsfiddle.net/y6sc0g4k/2/
There is no reasons to use the name
attribute at all. 完全没有理由使用
name
属性。 If you dont need to bind anything in the value
, you also dont have to use ng-value
, use just value
. 如果您不需要在
value
绑定任何内容,则也不必使用ng-value
,只需使用value
。 look over the example here: 在这里查看示例:
https://docs.angularjs.org/api/ng/input/input%5Bradio%5D https://docs.angularjs.org/api/ng/input/input%5Bradio%5D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.