Angular 2 prevent enter from submitting in template-driven form

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

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

&
9条回答
  •  别那么骄傲
    2021-02-01 12:12

    I know i am late, but may be i got proper solution for this,

    if you are using <button> then just define

    rather not defining it or defining it as type="submit" because if you dont define it, it will submit your form.

    Same if you are using then also define

     
    

    and this will work.

    -- Edited As @Chrillewoodz comment.

    If you wish to do some specific process on submit/click You can add click event to button, and in that you can do what ever you want.

    If you want Form tag in angular ts files, then you can use @ViewChild.

提交回复
热议问题