Looking to extract the value upon form submission in Angular, here is the code:
In my Typescript:
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public formBuilder: FormBuilder, public alertCtrl: AlertController,
public loadingCtrl: LoadingController) {
this.memleticsForm = formBuilder.group({
changeType: [{}, Validators.required]
});
}
memleticsSubmitForm(form) {
console.log(form);
}
Html:
<form name="learningtestForm" [formGroup]="memleticsForm" (submit)="memleticsSubmitForm(memleticsForm.value)" novalidate>
<table>
<tr>
<th>Question</th>
<th>0</th>
<th>1</th>
<th>2</th>
</tr>
<tr>
<td>You have a personal or private interest or hobby that you like to do alone.</td>
<td>
<input type="radio" formControlName="changeType" [value]=0>
</td>
<td>
<input type="radio" formControlName="changeType" [value]=1>
</td>
<td>
<input type="radio" formControlName="changeType" [value]=2>
</td>
</tr>
</table>
<button ion-button block color="secondary" end type="submit">Submit</button>
Upon clicking and submitting the button, the output on the console.log shows "Object {changeType: 2}"
The goal is to only retrieve the "2" and use it for calculations like this:
memleticsSubmitForm(form) {
var x = form * 5;
console.log(x); // if 2 is selected, display should be 10
}