Reputation: 141
I have one matInput field and a mat-icon(edit icon). When I click on the edit icon I need to perform the following operations
enable the input text box,
sets focus to it,
and auto-selects all the text in that.
Tried '$event.target.select()'. But it is not working. How can I do that? Thanks in advance.
.html file
<mat-form-field class="input-style">
<input matInput[(ngModel)]="name"(click)="$event.target.select()">
{{value}}
</mat-form-field>
<button mat-icon-button color="primary">
<mat-icon (click)="$event.target.select()">edit</mat-icon>
</button>
.ts file
export class Sample {
public value:string ="sample";
}
Upvotes: 0
Views: 1269
Reputation: 58523
You can do that with local elementRef var
:
<mat-form-field class="input-style">
<input matInput #inputRef [(ngModel)]="name">
{{value}}
</mat-form-field>
<button mat-icon-button color="primary">
<mat-icon (click)="inputRef.select()">edit</mat-icon>
</button>
Upvotes: 1