简体   繁体   English

Ionic 2 - 如何使用离子原生物体中没有的cordova插件

[英]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.

相关问题 如何将Native Cordova插件集成到Ionic Framework中? 相机图片背景 - How do I integrate Native Cordova Plugin in Ionic Framework? camerapicturebackground 如何在 Ionic 4 中使用cordova firebase.dynamiclinks 插件? - How do I use cordova firebase.dynamiclinks plugin in Ionic 4? 如何在 Ionic 4 中使用 Ionic 3 Cordova 插件? - How can I use a Ionic 3 Cordova plugin in Ionic 4? 具有离子和电容器的PWA,本机插件抱怨Cordova在浏览器和设备上不可用 - PWA with ionic and capacitor, native plugin complains cordova not available, on browser and device 结合使用Cordova插件和IONIC而非ionic-native - Using Cordova plugin with IONIC not ionic-native 我应该为 Ionic 4 使用 cordova 插件吗? - Should I use cordova plugin for Ionic 4? 如何添加带有ionic / ionic 2 / ionic 3 / ionic 4 / ionic 5的本地cordova插件? - How to add a local cordova plugin with ionic / ionic 2 / ionic 3 / ionic 4 / ionic 5? 如何在ionic 3中使用cordova插件蓝牙? - How to use the cordova plugin bluetoothle in ionic 3? 如何使用这个自定义离子 Cordova 插件? - How to use this Custom Ionic Cordova plugin? 如何在离子项目中使用自定义cordova插件? - How to use custom cordova plugin in ionic project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM