1

Estoy haciendo un formulario en Angular 10 y tengo una parte donde utilizo radio buttons junto a *ngFor. Se trata de un cuestionario que permite al usuario contestar a varias preguntas, pero el problema es que se supone que solamente se tendría que poder elegir una opción, pero me deja seleccionar más de una. Este es mi código

<h2 id="pregunta" *ngFor="let questions of question; let i=index"><div *ngIf="i<1">
          {{i}}
          {{questions.question}}
        
        <form [formGroup]="form" *ngFor="let answers1 of answer1; let j=index"  method="post"> 
          
          <input id="answers1{{j}}" type="radio" name="preg1" value={{answers1.id}}/><label
          for="answer2">{{answers1.answer}}</label>

</form>

<button id="boton" class="button" type="submit"(click)="onSubmit()">Siguiente</button>

Gracias de antemano por la respuesta

1
  • 1
    El *ngFor no debe ir en el formulario sino en el input, o en todo caso un contenedor que tenga dentro tu input y tu label, algo mas o menos así: <section *ngFor="let answers1 of answer1; let j=index"><input ... ... </label></section>. ;)
    – Israel-ICM
    el 5 feb. 2021 a las 20:00

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.