angular2 submit form by pressing enter without submit button

前端 未结 14 1679
长情又很酷
长情又很酷 2020-12-13 05:13

Is it possible to submit a form that does not have submit button (by pressing enter) example :

&
相关标签:
14条回答
  • 2020-12-13 06:08

    Edit:

      <form (submit)="submit()" >
        <input />
        <button type="submit" style="display:none">hidden submit</button>
      </form>
    

    In order to use this method, you need to have a submit button even if it's not displayed "Thanks for Toolkit's answer"

    Old Answer:

    Yes, exactly as you wrote it, except the event name is (submit) instead of (ngSubmit):

    <form [ngFormModel]="xxx" (submit)="xxxx()">
      <input [(ngModel)]="lxxR"   ngControl="xxxxx"/>
    </form>
    

    0 讨论(0)
  • 2020-12-13 06:09

    You can also add (keyup.enter)="xxxx()"

    0 讨论(0)
提交回复
热议问题