Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove underline of mat-select component

I am using basic mat-select component in my project.

 <mat-form-field>
     <mat-select placeholder="Favorite food">
       <mat-option *ngFor="let food of foods" [value]="food.value">
          {{food.viewValue}}
        </mat-option>
    </mat-select>
 </mat-form-field>

how can i remove the underline,I have tried this answer too still no result.

like image 979
PGH Avatar asked Aug 28 '18 11:08

PGH


People also ask

How do you remove mat-select arrows?

to the component style's sheet or the styles. scss of your angular app. Caution this will remove every arrow in mat-select. if you want to remove arrow for a few ones just add a class to mat-form-field and nest your class in the scss file.

What is compareWith in mat-select?

The compareWith just literally compares objects by some given values and the checkboxes get selected, if it returns true . In my code, I decided to go with the ng-Model binding but it works with formControl as well: <mat-form-field>


2 Answers

You can do this:

::ng-deep .mat-form-field-underline {   display: none; } 

StackBlitz

enter image description here

like image 175
camden_kid Avatar answered Oct 05 '22 02:10

camden_kid


You can also use the appearance property on the <form-field> . Setting appearance="none" will remove the underline without any css hack. And you can also get rid of ::ng-deep which is not recommended.

So your code will be like this.

<mat-form-field appearance="none">
 <mat-select placeholder="Favorite food">
   <mat-option *ngFor="let food of foods" [value]="food.value">
      {{food.viewValue}}
    </mat-option>
  </mat-select>
</mat-form-field>

For more information on appearance, you can check here. https://material.angular.io/components/form-field/overview#form-field-appearance-variants

like image 45
Ankit Agarwal Avatar answered Oct 05 '22 01:10

Ankit Agarwal