Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker in angular shown at bottom

I am facing an issue with datepicker I am using for angular2. I tried the code from https://material.angular.io/components/datepicker/examples. The output shown in this site is what I need, but instead I am getting the calendar shown at the bottom of the page after footer. There are no CSS changes given in the example.

I am using the following code.

HTML:

<mat-form-field>
 <input matInput [matDatepicker]="picker" placeholder="Choose a date">
 <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
 <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

TS:

import {Component} from '@angular/core';

@Component({
  selector: 'datepicker-overview-example',
  templateUrl: 'datepicker-overview-example.html',
  styleUrls: ['datepicker-overview-example.css'],
})
export class DatepickerOverviewExample {}

Screenshots : Output I need (from example)

Output I am getting

like image 993
Vishwa Patel Avatar asked Jan 03 '23 22:01

Vishwa Patel


1 Answers

It looks like you're missing the theming for your app. There should also be a warning in the console that no default theme was found.

Add the following line to your global stylesheet file (most likely styles.css):

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

Alternatively:

<head>
    <!-- Content goes here -->
    <link rel="stylesheet" href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css">
    <!-- More content goes here -->
</head>
like image 85
Edric Avatar answered Jan 05 '23 16:01

Edric