Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Input Select All on Click?

Pretty straight-forward question. When I click on an input field I want to select-all the text so when I start typing it over-writes what was previously there. Anyone know how to do this?

like image 751
Jus10 Avatar asked Nov 27 '22 08:11

Jus10


2 Answers

Seems the following should work:

<input matInput (click)="$event.target.select()">

Example

like image 131
yurzui Avatar answered Dec 05 '22 04:12

yurzui


What worked best for me is onfocus="this.select()"

<input matInput onfocus="this.select()">
like image 29
NobodySomewhere Avatar answered Dec 05 '22 04:12

NobodySomewhere