【问题标题】:How to use cordova plugin cordova-plugin-inline-datepicker?如何使用cordova插件cordova-plugin-inline-datepicker?
【发布时间】:2018-11-05 20:59:17
【问题描述】:

我正在开发一个 ionic 4 应用并想使用 cordova 插件cordova-plugine-inline-datepicker

而不是原生 ionic datepicker 插件,但出现错误

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>

【问题讨论】:

    标签: cordova ionic-framework datepicker ionic4


    【解决方案1】:

    解决方案:我是这样安装插件的:

    npm i cordova-plugin-inline-datepicker
    

    但正确的做法是:

    ionic cordova plugin add cordova-plugin-inline-datepicker
    

    现在插件在插件列表中比较,错误不再比较。

    【讨论】:

    • 您是否让插件实际输出日期选择器?我正在使用 Ionic 5,但没有让插件显示日期选择器。我认为“创建”正在工作,因为 ID 已添加到 inline-datepicker 元素中,但“显示”上没有任何反应。很想知道你是如何体验插件@Iva Pesa
    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多