Jus10
Jus10

Reputation: 15679

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?

Upvotes: 7

Views: 13345

Answers (3)

NobodySomewhere
NobodySomewhere

Reputation: 3225

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

<input matInput onfocus="this.select()">

Upvotes: 8

yurzui
yurzui

Reputation: 214047

Seems the following should work:

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

Example

Upvotes: 32

Jialzate
Jialzate

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

Related Questions