如何为该表单分配表单控件,我需要获取表单值。
import { Component } from '@angular/core';
import { FormGroup } from '@angular/forms';
@Component({
selector: 'app-e-mat-login',
templateUrl: './e-mat-survey-forms.component.html',
styleUrls: ['./e-mat-survey-forms.component.scss']
})
export class EMatSurveyComponent {
//myForm:FormGroup;
questions:any = [
{question:'Who is your First Prime Minister Of India?', options:['Dr.Manmohan Singh', 'Chandrashekar Ajadh','Mahatma Gandhi','Jyothirao Pule'], name:'answer1'},
{question:'Who is your Second Prime Minister Of India?', options:['Dr.Manmohan Singh', 'Chandrashekar Ajadh','Mahatma Gandhi','Jyothirao Pule'], name:'answer2'},
{question:'Who is your First lady Prime Minister Of India?', options:['Dr.Manmohan Singh', 'Chandrashekar Ajadh','Mahatma Gandhi','Jyothirao Pule'], name:'answer3'}
];
constructor( ) { }
ngOnInit() {
}
getAnswers():void{
alert();
}
}
<form name="survay-form">
<div *ngFor="let x of questions">
{{questions.indexOf(x) + 1 + " . "}}{{x.question}}<br/>
<div *ngFor = "let y of x.options">
<input type = "radio" [name] = 'x.name'/> {{y}}
</div><br/>
<button type="button" name="button" (click)="getAnswers();" class="mat-raised-button" *ngIf="questions.indexOf(x) == questions.length-1">Submit</button>
</div>
</form>