Angular - Submit a form programmatically

后端 未结 5 519
深忆病人
深忆病人 2021-02-07 02:40

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

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 03:01

    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();
    }
    

提交回复
热议问题