【发布时间】:2019-06-20 23:50:44
【问题描述】:
我试图在我的 ionic3 应用程序中包含一个 WheelSelector(Ionic Native 的轮子选择器插件),但是当我尝试将 WheelSelector 导入并添加到我的 app.module.ts @NgModule 中的提供者列表中时,我收到错误:“类型 'WheelSelectorOriginal' 不可分配给类型 'Provider'。”
我正在尝试遵循这个简单的教程: https://ionicacademy.com/wheel-picker-ionic/
我已通过在我的项目文件夹中执行以下操作来安装插件:
ionic cordova plugin add cordova-wheel-selector-plugin
npm install --save @ionic-native/wheel-selector
最终,我根本无法让插件工作。
我已尝试从两者中导入 WheelSelector:
'@ionic-native/wheel-selector'
'@ionic-native/wheel-selector/ngx'
如果我使用 ngx 版本,我不再收到上面的赋值错误,但是我收到一个新的运行时错误,指出 Object(...) is not a function。
app.module.ts:
import { WheelSelector } from '@ionic-native/wheel-selector';
...
@NgModule({
...
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
WheelSelector
]
home.ts:
import { Component } from '@angular/core';
import { NavController, ToastController } from 'ionic-angular';
import { WheelSelector } from '@ionic-native/wheel-selector';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
dummyJson = {
days: [
{description: 'Mon'},
{description: 'Tue'},
{description: 'Wed'},
{description: 'Thu'},
{description: 'Fri'},
{description: 'Sat'},
{description: 'Sun'}
],
people: [
{description: 'Joe'},
{description: 'John'},
{description: 'Max'}
]
};
constructor(public navCtrl: NavController,
private toastCtrl: ToastController, private selector: WheelSelector) {}
openPicker(){
this.selector.show({
title: 'select your contact',
positiveButtonText: 'yes',
negativeButtonText: 'no',
items:[
this.dummyJson.days,
this.dummyJson.people
],
defaultItems: [
{index:0, value: this.dummyJson.days[4].description},
{index:1, value: this.dummyJson.people[1].description},
]
}).then(result=>{
let msg = 'woo';
let toast = this.toastCtrl.create({
message: msg,
duration: 4000
});
toast.present();
});
}
}
如果我出错了,我们将不胜感激!谢谢!
【问题讨论】: