Ionic framework 在ionic框架中使用cordova插件而不使用ionic native
我发现了一个为codova制作的插件:Ionic framework 在ionic框架中使用cordova插件而不使用ionic native,ionic-framework,ionic2,cordova-plugins,Ionic Framework,Ionic2,Cordova Plugins,我发现了一个为codova制作的插件: 文档描述了如何直接使用对象Honeywell,而不是如何导入app.module并进行适当的调整。 我还没有找到关于爱奥尼亚原生开发或cordova插件迁移到爱奥尼亚2的清晰文档。 请提供有关如何将任何cordova插件导入现代爱奥尼亚2的指南 更新:在我的例子中,因为我有一个由插件创建的全局变量,所以我在@Component decorator之前声明该变量。但这一技巧打破了依赖注入系统 import { Component, NgZone } fro
文档描述了如何直接使用对象Honeywell,而不是如何导入app.module并进行适当的调整。 我还没有找到关于爱奥尼亚原生开发或cordova插件迁移到爱奥尼亚2的清晰文档。
请提供有关如何将任何cordova插件导入现代爱奥尼亚2的指南
更新:在我的例子中,因为我有一个由插件创建的全局变量,所以我在@Component decorator之前声明该变量。但这一技巧打破了依赖注入系统
import { Component, NgZone } from '@angular/core';
import { NavController } from 'ionic-angular';
declare var Honeywell;//declare the global created by the plugin
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
barcode: string;
constructor(public navCtrl: NavController, public zone: NgZone) {
Honeywell
.onBarcodeEvent( ... );
}
}
在你需要的任何提供者/页面的顶部使用“霍尼韦尔”就足够了,没有必要修改app.module.ts,它不是一个可以处理的依赖项
declare let Honeywell: any;
然而,我创建了一个TypeScript文件来存根这些方法并调用插件
import { Injectable } from '@angular/core';
import { IonicNativePlugin } from '@ionic-native/core';
declare let Honeywell: any;
@Injectable()
export class HoneywellBarcodeScanner extends IonicNativePlugin {
onLog(success, error, args?): Promise<any> {
return Honeywell.onLog(success, error, args);
}
onBarcodeEvent(success, error, args?): Promise<any> {
return Honeywell.onBarcodeEvent(success, error, args);
}
onFailureEvent(success, error, args?): Promise<any> {
return Honeywell.onFailureEvent(success, error, args);
}
barcodeReaderPressSoftwareTrigger(success, error, args?): Promise<any> {
return Honeywell.barcodeReaderPressSoftwareTrigger(success, error, args);
}
}
然后在app.module.ts中
providers: [
{
provide: HoneywellBarcodeScanner,
useFactory: PluginFactories.honeywellBarcodeScannerFactory,
deps: [Platform]
},
]
在你需要的任何提供者/页面的顶部使用“霍尼韦尔”就足够了,没有必要修改app.module.ts,它不是一个可以处理的依赖项
declare let Honeywell: any;
然而,我创建了一个TypeScript文件来存根这些方法并调用插件
import { Injectable } from '@angular/core';
import { IonicNativePlugin } from '@ionic-native/core';
declare let Honeywell: any;
@Injectable()
export class HoneywellBarcodeScanner extends IonicNativePlugin {
onLog(success, error, args?): Promise<any> {
return Honeywell.onLog(success, error, args);
}
onBarcodeEvent(success, error, args?): Promise<any> {
return Honeywell.onBarcodeEvent(success, error, args);
}
onFailureEvent(success, error, args?): Promise<any> {
return Honeywell.onFailureEvent(success, error, args);
}
barcodeReaderPressSoftwareTrigger(success, error, args?): Promise<any> {
return Honeywell.barcodeReaderPressSoftwareTrigger(success, error, args);
}
}
然后在app.module.ts中
providers: [
{
provide: HoneywellBarcodeScanner,
useFactory: PluginFactories.honeywellBarcodeScannerFactory,
deps: [Platform]
},
]