Search code examples
angularkeyup

How to detect @ in angular?


Someone know if it's possible to detect a @ in a input in angular ?

I can use :

(keyup.enter)="alert()"

But I need to do my method for @

Thank you if you have the solution!


Solution

  • Angular pseudo-events still have a few shortcomings, especially for symbols and as of now, @ is one of them. One workaround would be to use keypress and check for the key.

    (keypress)="onPress($event)"
    
    onPress(e: KeyboardEvent) {
        if (e.key === '@') {
            // Do something on press of @
        }
    }
    

    Or

    (keypress)="$event.key === '@' ? onPress() : null"
    
    onPress(e: KeyboardEvent) {
        // Do something on press of @
    }