Angular - Submit a form programmatically

后端 未结 5 517
深忆病人
深忆病人 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:07

    I think you should get ngForm in your code. So, rewrite your code as follows:

    and in your ts file:

    @ViewChild('testForm') testFormElement: NgForm;
    
    public testMethod(): void {
      // Below: This works for me.
      this.testFormElement.ngSubmit.emit();
    }
    
    public yourSaveMethod(): void {
      // post your model here.
    }
    

提交回复
热议问题