Is it possible to submit a form that does not have submit button (by pressing enter) example :
<form [ngFormModel]="xxx" (ngSubmit)="xxxx()">
<input [(ngModel)]="lxxR" ngControl="xxxxx"/>
</form
Is it possible to submit a form that does not have submit button (by pressing enter) example :
<form [ngFormModel]="xxx" (ngSubmit)="xxxx()">
<input [(ngModel)]="lxxR" ngControl="xxxxx"/>
</form
maybe you add
keypress
orkeydown
to the input fields and assign the event to function that will do the submit when enter is clickedyour template would look like this
And you function inside the your class would look like this
I prefer
(keydown.enter)="mySubmit()"
because there won't be added a line break if the cursor was somewhere within a<textarea>
but not at its end.adding an invisible submit button does the trick
<input type="submit" style="display: none;">
Edit:
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)
:You can also add
(keyup.enter)="xxxx()"
This way is much simple...