Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "mat-form-field" and "mat-input-container"

Tags:

I created this field in the form:

<mat-form-field class="example-full-width">   <mat-input-container floatPlaceholder="auto" flex="100">     <input matInput [(ngModel)]="evento.email" name="email" type="email" placeholder="Email para Contatos" email required [errorStateMatcher]="formMatcher">   </mat-input-container>   <mat-hint>Este será o endereço de e-mail oficial do evento.</mat-hint>   <mat-error *ngIf="formControl.hasError('email') && !formControl.hasError('required')">     Por favor insira um e-mail com formato válido.   </mat-error>   <mat-error *ngIf="formControl.hasError('required')">     Este campo é <strong>obrigatório.</strong> Não esqueça de preenchê-lo.   </mat-error> </mat-form-field> 

If I use mat-form-field and mat-input-container at same time, I get 2 repeated labels and 2 lines above the input box.

I have to use only one of these, but which should I use? To make that decision I need to know when it's best to use each one. Can anyone help explaining this? I couldn't find it in http://material.angular.io

like image 715
NaN Avatar asked Mar 15 '18 14:03

NaN


People also ask

What is the use of mat-form-field?

The <mat-form-field> is a component that is used to wrap multiple MAT components and implement common text field styles of the form-field such as hint message, underlines, and floating label. These five MAT components are designed to work inside the form-field: <mat-chip-list>

What is Mat input?

matInput is a directive that allows native <input> and <textarea> elements to work with <mat-form-field> .

Should create mat-form-field must contain a MatFormFieldControl?

Error: mat-form-field must contain a MatFormFieldControlThis error occurs when you have not added a form field control to your form field. If your form field contains a native <input> or <textarea> element, make sure you've added the matInput directive to it and have imported MatInputModule .


1 Answers

The component was renamed from mat-input-container to mat-form-field (I think during the v2.0.0 beta), but the old selector was still supported in v5.x. In v6.x, mat-input-container is no longer supported. So you should use the new name mat-form-field.

like image 82
G. Tranter Avatar answered Sep 24 '22 08:09

G. Tranter