Angular 角度区分键down.enter用于移动与桌面中的文本区域

Angular 角度区分键down.enter用于移动与桌面中的文本区域,angular,chat,enter,Angular,Chat,Enter,我目前正在开发一个聊天平台,其中有一个使用textarea(用户在其中键入消息)的消息输入框。按Enter键允许用户发送消息。然而,我想知道是否有可能区分桌面视图和移动视图的输入键行为,就像这样- 如果用户按下文本区域字段中的enter键: 1.桌面视图:用户能够发送消息 2.移动视图:在textarea字段中创建新行,不发送消息 message.component.html <textarea autosize [minRows]="1" [maxRows]="10" [(ngModel

我目前正在开发一个聊天平台,其中有一个使用textarea(用户在其中键入消息)的消息输入框。按Enter键允许用户发送消息。然而,我想知道是否有可能区分桌面视图和移动视图的输入键行为,就像这样-

如果用户按下文本区域字段中的enter键:
1.桌面视图:用户能够发送消息
2.移动视图:在textarea字段中创建新行,不发送消息

message.component.html

<textarea autosize [minRows]="1" [maxRows]="10" [(ngModel)]="messageToSend"
    (keydown.enter)="sendMessage($event)" placeholder="Type a message"></textarea>

谢谢你的帮助

如果需要检查屏幕大小,可以尝试

sendMessage(event: KeyboardEvent) {
    const message: Message = {
      id: this.id,
      date: new Date(),
      body: this.message,
    };
    this.chatService.sendChatMessage(id, message).subscribe();
}
if (window.matchMedia('screen and (max-width: 768px)').matches) {
   console.log('Screen is less then 768')
}