Select 在 IE11 的 angular2 中点击输入文本字段中的文本

Select text in input text field on click in angular2 in IE11

我有一个文本输入。当输入获得焦点时,我想 select 输入内的文本。 我在 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 way.There 是在 Angularjs using 指令中执行此操作的。我可以在 Angular2 中实现同样的效果吗?它也适用于 Firefox、Chrome 和 IE。

谢谢

您可以使用 Angular 2 提供的 (focus) 事件,如此 plunker

<input type="text" name="Description" placeholder={{description}} [(ngModel)]="description" maxlength="20" (focus)="$event.target.select()">
  <div *ngIf="selectedValue">{{selectedValue}}</div>