Deimos620
Deimos620

Reputation: 301

Datepicker for Angular 4

I am trying to add datepicker to Angular 4 based application. I tried to use ng2-datepicker. After install ng2-datepicker via npm I imported module like this:

import {DatePickerModule} from 'ng2-datepicker-bootstrap';

But webpack says can not find DatePickerModule. And I've tried to use ng2-eonasdan-datetimepicker, I imported it in app.module.ts like this:

import {A2Edatetimepicker} from 'ng2-eonasdan-datetimepicker';

@NgModule({
  imports: [
    A2Edatetimepicker
  ]
})

and webpack says:

ERROR in A2Edatetimepicker is not an NgModule

I am not sure what's wrong. Is there any cool datepicker for Angular 4? Or Did I do something wrong? Please, help me to fix this problem.

Upvotes: 4

Views: 8539

Answers (2)

Ricky
Ricky

Reputation: 36

Check out this npm package. It allows you to just simply add a directive to your input or element and is designed for both single and date range.

<input type="text" placeholder="Input Date" date-picker (dateselected)="dateSelected($event)" />

date picker directive

Upvotes: 0

Melchia
Melchia

Reputation: 24224

run

npm install ng2-datepicker --save

then in your root module:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgDatepickerModule } from 'ng2-datepicker';

@NgModule({
  imports: [
    BrowserModule,
    NgDatepickerModule
  ],
  declarations: [ AppComponent ],
  exports: [ AppComponent ]
})
export class AppModule {}

Upvotes: 3

Related Questions