如何在离子2中使用非原生cordova插件 [英] How to use non native cordova plugins in ionic 2

查看:104
本文介绍了如何在离子2中使用非原生cordova插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此cordova插件 https://github.com/honza889/cordova Ionic v2应用程序中的-plugin-kiosk

I am trying to use this cordova plugin https://github.com/honza889/cordova-plugin-kiosk in an Ionic v2 App.

基本上在使用 cordova插件在cordova中安装插件之后添加https:// github.com/honza889/cordova-plugin-kiosk.git 该插件已启用并正常工作。

Basically after installing the plugin in cordova with cordova plugin add https://github.com/honza889/cordova-plugin-kiosk.git the plugin is enabled and working.

但我找不到方法使用插件的方法。

But I can't find a way to use the plugin's methods.

window.plugins 未定义

cordova 未定义。

我试图在app.component.ts中导入插件但我无法弄清楚正确的道路。

I have tried to import the plugin in app.component.ts but I can't figure out the right path.

有没有人知道在Ionic V2应用程序中使用非本机插件的方法(文档和资源已过时或引用到原生插件)。

Does anyone know a way to use non native plugins in an Ionic V2 app (the documentation and resources are outdated or referring to native plugins).

提前致谢

推荐答案

你应该能够简单地访问 Kiosk代码中的插件变量。打字稿编译器不会知道该变量,因此您必须先声明它:

You should be able to simply access the KioskPlugin variable in your code. The typescript compiler will not know that variable, so you have to declare it first:

declare let KioskPlugin: any;

@Component({
  ...
})
export class TestPage {

  ...

  exitKiosk() {
    KioskPlugin.exitKiosk();
  }
}

这篇关于如何在离子2中使用非原生cordova插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆