How to hide / remove the underlined input of Angular Material?
Update:
Import MdInputDirective
import {MdInputDirective} from '@angular/material';
In compoent, do the following:
@ViewChild('input') input: MdInputDirective;
ngOnInit(){
this.input.underlineRef.nativeElement.className = null;
}
In html add link #input
:
<md-input-container #input>
<input mdInput placeholder="Last 4 SSN">
</md-input-container>
Original:
Try css:
::ng-deep .mat-input-underline {
display: none;
}
source to share
If you're using google-landed mat-form-field
instead of md-input-container
here, here are your two options.
- Just comment out the field
mat-form-field
and use your own styles. - See other appearance options available for in the documentation .
mat-form-field
source to share
For me it worked without ::ng-deep
. Using Angular 6.1.10 like this:
<form>
<mat-form-field class="no-line">
<input type="text"
matInput
field="label"
[matAutocomplete]="auto"
[formControl]="formControl"/>
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{ food.label}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
.no-line .mat-form-field-underline {
display: none;
}
source to share
I played around with the view property a bit and found that if you enter the value "none" (or any other unsupported value), you get a clear input. appearance
mat-form-field
Code:
<mat-form-field appearance="none">
<mat-label>"None" form field</mat-label>
<input matInput placeholder="Placeholder">
</mat-form-field>
StackBlitz demo (edited from the official angular demo).
The original example can be found here: Options for the appearance of a form field .
I admit this is a bit of a hack.
source to share