Angular2 - Validate and submit form from outside

后端 未结 8 2128
一个人的身影
一个人的身影 2020-11-30 22:44

I have a simple form that looks like this

...

and need to

8条回答
  •  無奈伤痛
    2020-11-30 23:04

    Found out how to do it:

    • trigger submit with .ngSubmit.emit()
    • get form status with .form.valid

    Example:

    ...

    Edit: As @yuriy-yakovenko has pointed out, you should add in your component code the following:

    @ViewChild('documentEditForm') documentEditForm: FormGroupDirective; 
    

    And don't forget to import the FormGroupDirective if you haven't done yet

提交回复
热议问题