0

I've followed the guide on how to install angular material. First I added it via the cli

ng add @angular/material

In the app.module.ts I've added the following additional lines:

import {MatDatepickerModule} from '@angular/material/datepicker'; 
import { MatNativeDateModule } from '@angular/material/core';



imports: [
    [...],
    MatDatepickerModule,
    MatNativeDateModule 
  ],
  providers: [MatDatepickerModule, MatNativeDateModule],

and in my HTML file I tried to create a datetimepicker

<mat-form-field color="accent" appearance="fill">
    <input matInput [matDatepicker]="picker1">
    <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
    <mat-datepicker #picker1></mat-datepicker>
</mat-form-field>

Unfortunately, the styling doesn't work at all. It looks like this:

enter image description here

Am I missing something?

Thanks in advance


edit: After adding the imports for MatFormFieldModule and MatInputModule it now looks like this which is still different from the tutorial:

enter image description here

8
  • hi mate, could u give any response if that solved ur problem? regards Commented Jul 27, 2020 at 10:14
  • did u stop ng serve and reserved :) Commented Jul 27, 2020 at 14:20
  • yes, the field does look different than before but not like the template. I imported the pink & blue-grey template so shouldn't all be dark? Commented Jul 27, 2020 at 14:25
  • I have prepared a stackblitz for u --> stackblitz.com/edit/angular-ivy-y739ny the background should be greyish. And u should see the suffix calendar icon. Commented Jul 27, 2020 at 14:26
  • Yeah that's what I would expect :) Commented Jul 27, 2020 at 14:29

1 Answer 1

2

To properly show the right styles you will also need to import the MatFormFieldModule and the MatInputModule to your app.module.ts file like so:

import { MatDatepickerModule } from '@angular/material/datepicker'; 
import { MatNativeDateModule } from '@angular/material/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';    

imports: [
    [...],
    MatDatepickerModule,
    MatNativeDateModule,
    MatFormFieldModule,
    MatInputModule
  ],
providers: [MatDatepickerModule, MatNativeDateModule]

You can see that you need them by analyzing the html which consists of <mat-form-field></mat-form-field> and the <input> tag has a matInput directive on it.

regards

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

1 Comment

Thanks for your answer! Unfortunately, it still doesn't look as expected :( I will update the original post

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.