Reputation: 15679
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?
Upvotes: 7
Views: 13345
Reputation: 3225
What worked best for me is onfocus="this.select()"
<input matInput onfocus="this.select()">
Upvotes: 8
Reputation: 214047
Seems the following should work:
<input matInput (click)="$event.target.select()">
Upvotes: 32
Reputation: 315
If you are using angular material 1.x, you can use md-select-on-focus
<md-input-container>
<label>Auto Select</label>
<input type="text" md-select-on-focus>
</md-input-container>
This link can help you md-select-on-focus
Upvotes: 1