I am aware 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?
This question is related to
angular
typescript
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
Another option:
this.form.value['nameOfControl']
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 use getRawValue()
this.formGroup.getRawValue().attribute
You can do by the following ways
this.your_form.getRawValue()['formcontrolname]
this.your_form.value['formcontrolname]
Source: Stackoverflow.com