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?
Angular Material Input Select All on Click?
Asked Answered
Indeed it does! ty –
Beatty
I realize the question asked specifically for when someone "clicks" on it... but I think it would be better to do with on focus:
(focus)="$event.target.select()"
That way if you are clicking around inside the field to move a cursor you wont end up re-selecting everything. –
Completion What worked best for me is onfocus="this.select()"
<input matInput onfocus="this.select()">
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
FYI: This is AngularJS, Angular2 does not have this –
Pomegranate
© 2022 - 2024 — McMap. All rights reserved.