Step 1
First, we have to install npm commands in our project.
npm install ngx-mydatepicker --save.commands
the above command is for adding external dependency.
Step 2
Add app.module.ts page with the below code for importing the refernce.
- import { NgxMyDatePickerModule } from 'NgxMyDatePickerModule ';
-
- @NgModule({
- imports: [ NgxMyDatePickerModule.forRoot() ],
- })
Step 3
Add your source component.ts page inside call IMyDateModel setting, The default date selection. Sunday has been marked in red color. The current date have to be marked on the calendar.
- import {
- INgxMyDpOptions,
- IMyDateModel
- } from 'ngx-mydatepicker';
- date = new Date();
-
- myOptions: INgxMyDpOptions = {
- dateFormat: 'dd.mm.yyyy',
- sunHighlight: true,
- markCurrentDay = true;
- };
-
- ngxdatepicker: any = {
- jsdate: new Date()
- };
-
- ngxdatepicker: any = {
- date: {
- year: 2018,
- month: 3,
- day: 17
- }
- };
-
- onDateChanged(event: IMyDateModel): void {
- console.log(event.formatted);
- });
Step 4
Add the source component.html page added ngx-mydatepicker HTML code.
- <div class="input-group"> <input class="form-control" style="float:none" placeholder="Select a date" ngx-mydatepicker name="mydate" [(ngModel)]="ngxdatepicker" [options]="myOptions" #dp="ngx-mydatepicker" (dateChanged)="onDateChanged($event)" /> <span class="input-group-btn">
- <button type="button" class="btn btn-default">
- <i class="glyphicon glyphicon-calendar"></i>
- </button>
- </span> </div>
I hope this blog mostly helpful for youe ngx-mydatepicker in Angular project.