2017-08-01 56 views
1

我有一個文本輸入。當輸入獲得焦點時,我想選擇輸入內的文本。 我在Angular2中編寫了下面的代碼,它在Google Chrome中完美工作,但在IE11中不起作用。在IE11的angular2中點擊輸入文本字段中的文本

<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中使用。

謝謝

+0

你嘗試使用(焦點)demonstarted? – Salander

+0

你想要這樣的東西嗎?:https://plnkr.co/edit/ia9dv530yxfnqaDHikaq?p = preview –

+0

@Salander:我已經嘗試過關注 –

回答

1

您可以使用angular2提供的(焦點)事件如本plunker

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