Angular - Submit a form programmatically

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

    Regarding "Angular - Submit a form programmatically" Here is code where a form submits itself. It works for me. Hope this helps.

    Component HTML:

    Component TypeScript:

    @ViewChild('myForm') myForm : ElementRef;
    
    ngAfterViewInit() {
      this.myForm.nativeElement.submit();
    }
    

提交回复
热议问题