0

Currently the input field looks like this:

enter image description here

One of my components has the following HTML:

<form class="example-form">
  <mat-form-field class="example-full-width">
    <input matInput placeholder="Favorite food" value="Sushi">
  </mat-form-field>

  <mat-form-field class="example-full-width">
    <textarea matInput placeholder="Leave a comment"></textarea>
  </mat-form-field>
</form>

My app.module.ts has the follwing:

enter image description here

Any reason why the input is not styled like in the examples?

enter image description here

4
  • did you included the material library with the ng add @angular/material command? it could be that you forgot to import the material theme if you had imported it by hand Commented Dec 12, 2019 at 9:09
  • i added the ng add @angular/material command before (indigo/pink) theme; nothing changed Commented Dec 12, 2019 at 9:11
  • Do you have 'FormsModule' or/and 'ReactiveFormsModule' also imported? Commented Dec 12, 2019 at 9:14
  • @PedroB.i added them now, but no change Commented Dec 12, 2019 at 9:30

1 Answer 1

1

Try to import Material Form Field Module in your NgModule. Also it is required to add Material CSS in your style.scss

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

And in app.module.ts add MatInputModule

import {MatInputModule,MatFormFieldModule} from '@angular/material';

// ....
imports: [
    MatFormFieldModule,
    MatInputModule,
    ...
],

Refer to the docs: Form-Field, and Example

Sign up to request clarification or add additional context in comments.

9 Comments

Do you have any online demo like on stackblitz ?
@rohan-humar not sure how to add ng add @angular/material to stackblitz
I have updated my answer. Please add Material CSS, and MatInputModule in your application.
The styles.css already contains @import "~@angular/material/prebuilt-themes/indigo-pink.css"; in the image in the post MatInputModule,MatFormFieldModule are included :) I will try to set up a stackblitz
Please see the demo on stackblitz.com/edit/angular-avlgjh
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.