0

My Angular 8 Material components are not rendering correctly .It should look like the example below: Angular Material Example

But it looks like this: Current UI

Here is the app.module.ts:

import { FormsModule } from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field';

@NgModule({
   declarations: [
   AppComponent,
   LoginComponent
],
imports: [
  BrowserModule,
  AppRoutingModule,
  BrowserAnimationsModule,
  FormsModule,
  MatFormFieldModule
],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

Here is the app.component.html

<div class="example-container">
<mat-form-field>
    <input matInput placeholder="Input">
</mat-form-field>

<mat-form-field>
    <textarea matInput placeholder="Textarea"></textarea>
</mat-form-field>

<mat-form-field>
    <mat-select placeholder="Select">
        <mat-option value="option">Option</mat-option>
    </mat-select>
</mat-form-field>

7
  • did you add material css to styles.scss ? Commented Nov 28, 2019 at 6:54
  • example theme: @import "~@angular/material/prebuilt-themes/indigo-pink.css"; Commented Nov 28, 2019 at 6:54
  • Yes I have,I imported the deeppurple-amber theme in the styles.scss Commented Nov 28, 2019 at 6:55
  • can you try stop and restart your ng serve ? Commented Nov 28, 2019 at 6:56
  • I tried that just now, same result as before Commented Nov 28, 2019 at 6:57

2 Answers 2

1

I think you should use MatSelectModule and MatInputModule

Because MatFormModule used for Matform

So your module should be like this

import { FormsModule } from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field';

import {MatSelectModule,MatInputModule} from '@angular/material/form-field';

@NgModule({
   declarations: [
   AppComponent,
   LoginComponent
],
imports: [
  BrowserModule,
  AppRoutingModule,
  BrowserAnimationsModule,
  FormsModule,
  MatFormFieldModule,
  MatSelectModule,
  MatInputModule
],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

and also you can import css in style.css file

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

WORKING DEMO

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

7 Comments

I have added the missing modules but it has made no difference
Your demo is working. I see that all my styles end in scss as apposed to you css. Would that be an issue?
I have copied your working code over to my app but it doesnt seem to work. Could I be missing some imports or modules?
Do you get an any exception?
No exceptions, it runs as normal but is not showing correctly
|
0

You have to add MatInputModule (for input and textareas) and MatSelectModule (for select) to your app.module.ts file.

You can see what is needed for component at the top of this pages:

material input component

material select component

1 Comment

I have added the modules as you have advised but it has made no difference

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.