如何通过带有For循环的角度从Mat-radio-group中获取选定的单选按钮值

问题描述 投票:1回答:1

我有一个复杂的对象,即如下所示

someName = [
{name: "John",id: "1",rating: ['0', '1', '2', '3', '4', '5']},
{name: "robert", id: "2", rating: ['0', '1', '2', '3', '4', '5']},
{name: "luv", id: "3", rating: ['0', '1', '2', '3', '4', '5']}
];

我想从中进行问卷调查,以确保他们在0-5之间对答案进行评分,现在当我如下图所示渲染HTML时>]

<ng-container *ngFor="let sort of someName; let i=index">
   <label id="example-radio-group-label">Rate your favorite section</label>
   <mat-radio-group aria-labelledby="example-radio-group-label" class="example-radio-group" [(ngModel)]="sectionRating">
      <mat-radio-button class="example-radio-button" *ngFor="let section of sort.sections" [value]="section">{{season}}</mat-radio-button>
   </mat-radio-group>
</ng-container>

这显示正确,但是当我选择第一个问题等级为1时,它也同时从所有其他等级中进行选择,并且我也想捕获我尝试过的所有这些等级[(ngModel)],但它仅给出一个值而不是数组

在我的.ts文件中,我给模型的引用为Array,如下所示:

sectionRating: any[] = [];

我有一个复杂的对象,例如,像someName = [{name:“ John”,id:“ 1”,rating:['0','1','2','3','4', '5']},{名称:“ robert”,id:“ 2”,评分:['0','1','2','3','4','5']},{名称:“ luv”,...

angular angular-material angular-template-form
1个回答
2
投票

您可以尝试使用,使用(change)事件,然后在本地变量中添加单击项。

© www.soinside.com 2019 - 2024. All rights reserved.