[英]Ionic 2 - How do I use a cordova plugin that is not available in ionic native
With the following command I installed a cordova plugin on my ionic2 project: 使用以下命令,我在ionic2项目上安装了一个cordova插件:
cordova plugin add cordova-plugin-rfduino
This plugin is not available in the Ionic Native. 此插件在Ionic Native中不可用。 How can I use the plugin in an ionic page?
如何在离子页面中使用插件? Can I export it somehow?
我可以以某种方式出口吗?
当您安装插件时,您可以从全局window
对象中使用它,但是rfduino
将无法理解什么是rfduino
对象及其类型,因此您必须将其声明为位于src/declarations.d.ts
的声明文件。 ,因此您只需在该文件中添加此行代码即可使用它
declare var rfduino: any;
I fixed it the following way: 我通过以下方式修复它:
0 - Install your plugin 0 - 安装你的插件
1- npm install typings --global 1- npm安装类型 - 全球
2 - On typings/index.d.ts put the following code: 2 - 在typings / index.d.ts上输入以下代码:
interface Window {
plugins: any;
}
3 - Then use the window the following way inside the page or component: 3 - 然后在页面或组件内使用以下方式的窗口:
constructor(platform: Platform) {
platform.ready().then(() => {
var blabla = window['cordova_plugin_that_was_installed'].function();
});
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.