How to use cordova plugin cordova-plugin-inline-datepicker


#1

I’m developing an ionic 4 app and want to use cordova plugin https://github.com/unumotors/cordova-plugin-inline-datepicker instead of native ionic datepicker plugin but I’m getting an error

Uncaught (in promise): TypeError: Cannot read property 'create' of undefined

Impostazioni.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,Platform } from 'ionic-angular';
declare var cordova:any;

@IonicPage()
@Component({
  selector: 'page-impostazioni',
  templateUrl: 'impostazioni.html',
})
export class ImpostazioniPage {
constructor(private platform: Platform) {

show(){
    this.platform.ready().then(() => {
      //alert('dentro');
      let element = document.querySelector('.inline-datepicker');
      let options = {
        'mode': 'date',//cordova.plugins.DatePicker.Mode.DATE'', // default is DATE_AND_TIME
        'date': new Date(),
      };
      let success = function (data) {
        // this callback is called everytime input is changed
        //document.querySelector('.date-label').innerText = new Date(data.date).toLocaleDateString();
        alert('success');
      }
      let error = function (data) {
        // this callback is called everytime input is changed
        //document.querySelector('.date-label').innerText = new Date(data.date).toLocaleDateString();
        alert('error: ' + data);
      }


      cordova.plugins.DatePicker.create(element, options,success, error);

        cordova.plugins.DatePicker.show(element, options,success, error);
    });
  }
}
}

impostazioni.html

<ion-content padding>
<div class="date-label" (click)="show()">No date selected</div>
<div class="inline-datepicker" ></div>
</ion-content>

What am I doing wrong?

Thank you for helping.


#2

I forgot to install the plugin in the project

ionic cordova plugin add cordova-plugin-inline-datepicker