我有一个文本输入。当输入接收焦点时,我想选择输入内部的文本。 我在 Angular2 中编写了以下代码,它在 Google Chrome 中完美运行,但在 IE11 中不起作用。
<input type="text" name="Description" id="Description" [(ngModel)]="Description" maxlength="20" (click)="$event.target.select()">
我也尝试过 (mouseup)="$event.target.select()"。它也适用于 Chrome,但不适用于 IE11。 我四处搜寻,试图找到 Angular2 的方式。在 Angularjs 中可以使用指令来做到这一点。我可以在 Angular2 中实现同样的功能吗?它也适用于 Firefox、Chrome 和 IE。
谢谢
最佳答案
您可以使用 angular2 提供的 (focus) 事件,如本 plunker 中所示。
<input type="text" name="Description" placeholder={{description}} [(ngModel)]="description" maxlength="20" (focus)="$event.target.select()">
<div *ngIf="selectedValue">{{selectedValue}}</div>
关于angular - 在 IE11 中单击 angular2 时选择输入文本字段中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45430835/