【发布时间】:2020-07-27 07:58:04
【问题描述】:
是否可以通过按键盘上的 Enter 来触发我的“添加”按钮?
////
这是表单中的最后一个 div,用于第三个间隙:
<div fd-form-item *ngIf="targetType.value != null">
<label fd-form-label for="input-showroom-hostname" [required]="true">URL:</label>
<fd-form-input-message-group>
<input
fd-form-control
type="text"
id="input-showroom-hostname"
placeholder="e.g. l2w.demo.hybris.com"
formControlName="hostname"
[state]="determineFormControlState(hostname)"
/>
<fd-form-message *ngIf="hasRequiredErrors(hostname)" [type]="'error'"> {{ REQUIRED }} </fd-form-message>
<fd-form-message *ngIf="hasShowroomUserRightsErrors(hostname)" [type]="'error'"> {{ SHOWROOM_USER_RIGHTS }}</fd-form-message>
<fd-form-message *ngIf="hasPatternErrors(hostname)" [type]="'error'"> {{ URL_PATTERN }} </fd-form-message>
</fd-form-input-message-group>
</div>
<br />
</div>
【问题讨论】:
-
是的,它是:(keydown.enter)="addShowroom()"
-
不需要任何东西来使它工作。
button元素已经触发click处理程序,当您在此按钮处于焦点时按 enter 时。无需更改 -
能否提供更多来自component.html和component.ts的代码,以便我们推断上下文?
-
我添加了完整的html
-
对我来说很好用:stackblitz.com/edit/angular-ivy-t49oov 按钮是否被禁用,是否有焦点?
标签: angular typescript keydown enter onkeydown