Angular 2 prevent enter from submitting in template-driven form

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

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

&
9条回答
  •  北海茫月
    2021-02-01 12:31

    To allow enter key to work in textareas but prevent from submitting form, you could modify as follows:

    In HTML template:

    ...
    

    In the component's class in the .ts code behind:

    handleEnterKeyPress(event) {
        const tagName = event.target.tagName.toLowerCase();
        if (tagName !== 'textarea') {
          return false;
        }
      }
    

提交回复
热议问题