I'm creating a custom form. I've created a custom form:
<form (ngSubmit)="onSubmit(contactForm)" #contactForm="ngForm">
....email input filed
<label class="label" for="experience">How did you find the booking experience?</label>
<select id="experience" #experience="ngModel"[ngModelOptions]="{standalone: true}">
<option selected>Choose...</option>
<option value="excellent">Excellent</option>
<option value="verygood">Very good</option>
<option value="good">Good</option>
<option value="fair">Fair</option>
<option value="poor">Poor</option>
</select>
<button type="submit " value="Send ">Send</button>
</form>
here is the typescript:
onSubmit(contactForm: NgForm) {
console.log("called");
if (contactForm.valid) {
const email = contactForm.value;
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
this.http.post('https://formspree.io/f/xnqolzjd',
{ replyto: email.email, experience: email.experience },
{ 'headers': headers }).subscribe(
response => {
console.log(response);
}
);
}
}
But my experience: email.experience
is blank in the object. It works when I hard code some value in the object itself. replyto: email.email
is fetching correct value. Please help.
question from:
https://stackoverflow.com/questions/65644652/how-to-fetch-value-of-a-dropdown-option-in-angular-form 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…