Ionic 2, Date Picker (cordova plugin). Property 'ANDROID_THEMES' does not exist in type 'typeof DatePicker'

I installed the Date Picker plugin in my project.

In the component with import { DataPicker } from 'ionic-native' top, if I use it as (with androidTheme parameter comment), it WORKS :

  let options = { date: new Date(), mode: 'date', // androidTheme: DatePicker.ANDROID_THEMES.THEME_HOLO_LIGHT }; DatePicker.show(options).then( (date) => { console.log('date_value:' + date) }).catch( (error) => { }); 

If I uncomment androidTheme:DatePicker.ANDROID_THEMES.THEME_HOLO_LIGHT , there will be an error during the build process:

Property ANDROID_THEMES 'does not exist for type' typeof DatePicker '

I did npm install ionic-native in the CLI in my project folder as as here , but that didn't fix the problem. This gives me the following result (which seems good to me):

`- ionic-native @2.0.3

npm WARN optional Failed to skip the optional dependency / chokidar / fsevents:

npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.15

When I look under [my project]\plugins\cordova-plugin-datepicker\www , it contains 3 folders corresponding to 3 platforms (ios, android, windows) with each JS file called "DatePicker.js" and that located under the android folder contained in the code:

 /** * Android themes */ DatePicker.prototype.ANDROID_THEMES = { THEME_TRADITIONAL : 1, // default THEME_HOLO_DARK : 2, THEME_HOLO_LIGHT : 3, THEME_DEVICE_DEFAULT_DARK : 4, THEME_DEVICE_DEFAULT_LIGHT : 5 }; 

If I look in [my project]\nodes_modules\ionic-native\dist\plugins\ , the datepicker.js file exists (of course), but does not contain the features of each platform.

What happened? Why datepicker.js under [my project]\nodes_modules\ionic-native\dist\plugins\ not contain the features of each platform, despite the fact that the plug-in was added to the project?

0
source share
1 answer

I found a job for him:

in [my project] \ nodes_modules \ ionic-native \ dist \ plugins [android | ios | windows] \ datepicker.js

At the end of the code it says:

 var datePicker = new DatePicker(); module.exports = datePicker; // Make plugin work under window.plugins if (!window.plugins) { window.plugins = {}; } if (!window.plugins.datePicker) { window.plugins.datePicker = datePicker; } 

Therefore, it makes datePicker (starting with lowercase) different from DatePicker (starting with upper case from ionic).

In the component where I requested it, I simply declare before the component:

 declare var datePicker: any; 

Then, inside this component, I changed my code to:

  let options = { date: new Date(), mode: 'date', androidTheme: datePicker.ANDROID_THEMES.THEME_HOLO_LIGHT }; DatePicker.show(options).then( (date) => { console.log('date_value:' + date) }).catch( (error) => { }); 

He works.

+1
source

All Articles