lundi 28 septembre 2020

I need some help to write nested ngFor loops in Angular

I need some help to write nested ngFor loops in Angular. Need to have always 3 same answers(radio buttons) for a loop of questions (checkboxes). my code:

<ng-container *ngFor="let daType of daTypes"> 
 <mat-checkbox [name]="daType" [(ngModel)]="data[daType]"></mat-checkbox>
 <mat-radio-group id="daTAs" name="daTAs" [(ngModel)]="data[daType]">
   <ng-container *ngFor="let daTA of ansYNU">
     <mat-radio-button [value]="daTA">  </mat-radio-button>
   </ng-container>
 </mat-radio-group>
</ng-container>

daTypes and ansYNU are both arrays of strings. By writing it like this all radio buttons act like one - if I check "yes" in the first question, and then "no" in second, the first "yes" doesn't stay checked. Can someone see where the Problem is?




Aucun commentaire:

Enregistrer un commentaire