0

How do I highlight the contents of a textbox in Angular? the following is not working. Currently using Material textbox.

Need to apply it conditionally, based on boolean variable highlightTextFlag, maybe with ngstyle .

Sample:

input::first-line { 
   background-color: green !important; 
}

Actual code:

<mat-form-field>
    <mat-label>Test</mat-label>   
    <input
        matInput 
        [ngStyle]="{'input::first-line': 'green' }"
    >
</mat-form-field>

enter image description here

How to highlight text inside an input field?

Angular Material: Highlight Words in a Textbox

1 Answers1

1

You can add the css in your component css file, but use a class name instead of the input selector as following:

.myInput::first-line{
//your css
}

And bind the class name to your Boolean variable in the component template as follows

<mat-form-field>
    <mat-label>Test</mat-label>   
    <input
        matInput 
        [class.myInput]=“myBooleanVar”
    >
</mat-form-field>
Ibrahim Rahhal
  • 323
  • 2
  • 9