Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

placeholder loaction in mat-input

I'm using angular6 with angular material to create this neat website.

I'm using a mat-form-field with mat-input so show a text input element with a placeholder text.

the placeholder text position has two states.

one! when the text input is empty and you are not focused into that element:

empty mat-input

and the other when you focused on the input text and/or you the input text is not empty

mat-input with text

I want the mat-input element to be in the 2nd state. to show the placeholder above the text input element even when there is no text in it and i'm not focused on that element.

I know i can make a work-around and add some sort of empty space to the value of the element.. but is there a more elegant way to achieve what I need?

thanks!!!

like image 852
ufk Avatar asked Sep 23 '18 18:09

ufk


People also ask

What is placeholder in angular?

Dynamic placeholder binding in Angular component emailPlaceholderText is a variable of type string in the Angular component. With property binding, placeholder is defined inside square brackets and the syntax is as follows. <input id="email" class="form-control" [placeholder]="emailPlaceholderText">


1 Answers

You can use floatLabel="always", which is the input property binding for mat-form-field

<mat-form-field style="width: 100%" floatLabel="always">
  <input matInput placeholder="Enter Name">
</mat-form-field>

Working Stackblitz

like image 188
Sivakumar Tadisetti Avatar answered Oct 08 '22 11:10

Sivakumar Tadisetti