Home > OS >  Angular - why key.enter is not working inside mat-menu
Angular - why key.enter is not working inside mat-menu

Time:06-23

I have the following input and I want to fire the event after pressing enter:

  <input
    matInput
    type="number"
    min="0"
    placeholder="0"
    (keyup.enter)="minValue($event)"
  />

I have also tried (keydown.enter)="minValue($event)" without success. How can a user type a value and when pressing enter call the minValue method?

Also, when I am clicking on the input field to type a value the input box dissapears before write anything.

Thanks a lot.

CodePudding user response:

Try like this:

.html

<input
matInput
type="number"
min="0"
placeholder="0"
[(ngModel)]="myValue"
(keyup.enter)="minValue(myValue)"
/>

.ts

  minValue(evt){
    console.log(evt)
  }

Demo

  • Related