Cannot find name 'DatePicker'. in ionic2

I already installed ionic-native and
ionic plugin add cordova-plugin-datepicker
Then import the DatePicker plugin in code:
import {DatePicker} from ‘ionic-native’;

The error occur on below line.
constructor(public navCtrl: NavController, public navParams: NavParams, public DatePicker: DatePicker)

The error message is: Cannot find name ‘DatePicker’.

Please import it in ap.module.ts as well and mention in it imports.

I already did:
In app.module.ts
import {DatePicker} from ‘ionic-native’;

@NgModule({
declarations: [
MyApp,
HomePage,
Signup,
DatePicker
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
Signup,
DatePicker
]

Well as per the documentation.

First run:
$ ionic plugin add --save cordova-plugin-datepicker
$ npm install --save @ionic-native/date-picker

Then you need to import from @ionic-native/date-picker like so:

import { DatePicker } from '@ionic-native/date-picker';

Also be sure you add the module to your app.module.ts

1 Like

When i installed this
npm install --save @ionic-native/date-picker

and run i get following error:
typescript: node_modules/@ionic-native/date-picker/index.d.ts, line: 1
Module ‘"/Users/Hassan/alstomWifi/node_modules/@ionic-native/core/index"’ has no exported member
’IonicNativePlugin’.

   L1:  import { IonicNativePlugin } from '@ionic-native/core';
   L2:  export interface DatePickerOptions {

Concering the IonicNativePlugin error, it is related to this github issue.

2 Likes

Thanks @kgaspar. It is working.

1 Like