Reputation: 3557
I'm using matInput. What I want is that the content in matInput is marked/highlighted so that if I press any key the text gets deleted. For example you double click a word in the search bar here in stackoverflow. How can I archieve that?
<mat-form-field>
<input matInput [(value)]="test">
</mat-form-field>
Upvotes: 1
Views: 2346
Reputation: 26170
Assuming you're using Angular 8, you can use @ViewChild
decorator to get a reference to your input
element. Then you select the input value within the ngAfterViewInit
lifecycle hook. In order to link the input
element with @ViewChild
, you can use a template reference variable (e.g. #food
).
Please have a look at the following StackBlitz
Please note that using
setTimeout
insidengAfterViewInit
prevents you from getting anExpressionChangedAfterItHasBeenCheckedError
.
Upvotes: 1