如何检测angular中的@?

How to detect @ in angular?

有人知道是否可以在 angular 的输入中检测到 @ 吗?

我可以使用:

(keyup.enter)="alert()"

但是我需要为@

做我的方法

有解决方法谢谢!

Angular 伪事件仍然有一些缺点,特别是对于符号,截至目前,@ 就是其中之一。一种解决方法是使用 keypress 并检查 key.

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

或者

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