Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/delete underline input Angular Material?

I have input element in Angular Material:

<md-input-container> <input type="text" mdInput placeholder=""> </md-input-container> 

When input has focus it displays underline. How to hide or remove that?

Seem I need to set null for underlineRef?

like image 302
Daniel Avatar asked Aug 07 '17 23:08

Daniel


People also ask

How do I Hide and display data in HTML?

As you can see in the above example, we can easily hide and display content using *ngIf and button (click) methods. If we want to hide the Display Data button when the content displays the Hide Data button when the data is hidden, we can also use the same concept on buttons.

How do I clear the input field in a form?

If you are using [ (ngModel)] directive to control your form input fields, then you can clear it by setting an empty string ( ' ') to the ngModel control property. We can also clear it by adding a reference to the input field and access that element inside the app component by using @ViewChild () decorator.

How to clear the input field of an app component?

We can also clear it by adding a reference to the input field and access that element inside the app component by using @ViewChild () decorator. #name is the reference added to the above input field.

Why can't I submit a form with a hidden input type?

If your open your browser console, you would see "ERROR Error: Input type "hidden" isn't supported by matInput." and if you tried to submit the form with type="hidden", then the form will be corrupt, only displaying part of the form values. A simple way of going around this issue is by using a CSS class on the mat-form-field tag:


1 Answers

I was playing a bit with the appearance property of mat-form-field and found that if you put a "none" value (or any other unsupported value), you will get clear input.

The 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: Form field appearance variants.

I admit, this is a little bit of a hack.

like image 63
jurl Avatar answered Sep 21 '22 09:09

jurl