Angular 2 prevent enter from submitting in template-driven form

后端 未结 9 1598
故里飘歌
故里飘歌 2021-02-01 11:54

I have forms that uses the template-driven blueprint, so something like this:

&
9条回答
  •  盖世英雄少女心
    2021-02-01 12:29

    This is what helped me:

    • the button that has to act as submitting one should be type="button"
    • that button should have (click)="onSubmit()" <- the method that will be called
    • and you can remove i.e. (ngSubmit)="onSubmit()" from

    I am not sure if there are side-effects of removing (ngSubmit) from the form. BTW: I observed that

    
    

    have disabled custom validators.

提交回复
热议问题