Angular - Submit a form programmatically.
I have a form group on the HTML and I want the component to submit the form\'s action with an email field in a post method. Ins
You can use ngNoForm
with your form to remove ngForm
handling and to add plain javascript handler.
you can use your code as follows:
Html file.
Ts File.
@ViewChild('testForm') testFormElement;
public currentUserEmail: string = '';
public testGroup = this.formBuilder.group({
Email: ''
});
constructor(formBuilder: FormBuilder) {
}
public testMethod(): void {
this.testFormElement.nativeElement.submit();
}