I am aware that I can get the values of a form using
JSON.stringify(this.formName.value)
However, I want to get a single value from the form.
How do I go about doing that?
I am aware that I can get the values of a form using
JSON.stringify(this.formName.value)
However, I want to get a single value from the form.
How do I go about doing that?
You can get value like this
this.form.controls['your form control name'].value
Yes, you can.
this.formGroup.get('name of you control').value
Dot notation will break the type checking, switch to bracket notation. You might also try using the get() method. It also keeps AOT compilation in tact I've read.
this.form.get('controlName').value // safer
this.form.controlName.value // triggers type checking and breaks AOT
for Angular 6+ and >=RC.6
.html
<form [formGroup]="formGroup">
<input type="text" formControlName="myName">
</form>
.ts
public formGroup: FormGroup;
this.formGroup.value.myName
should also work.
This code also works:
this.formGroup.controls.nameOfcontrol.value
You can do by the following ways
this.your_form.getRawValue()['formcontrolname]
this.your_form.value['formcontrolname]