【问题标题】:Ionic 2 - How do I use a cordova plugin that is not available in ionic nativeIonic 2 - 如何使用 ionic native 中不可用的 cordova 插件
【发布时间】:2017-03-08 22:29:09
【问题描述】:

通过以下命令,我在我的 ionic2 项目上安装了一个 cordova 插件:

cordova plugin add cordova-plugin-rfduino

该插件在 Ionic Native 中不可用。如何在离子页面中使用插件?我可以以某种方式导出它吗?

【问题讨论】:

    标签: cordova arduino ionic2 cordova-plugins rfduino


    【解决方案1】:

    当您安装插件时,您可以从全局 window 对象中使用它,但打字稿不会理解 rfduino 对象及其类型,因此您必须将其声明到位于的声明文件中src/declarations.d.ts,所以你只需在该文件中添加这行代码即可使用它

    declare var rfduino: any;
    

    【讨论】:

    • 不幸的是,这还不够。我修好了 - 看看我的答案。
    【解决方案2】:

    我通过以下方式修复它:

    0 - 安装你的插件

    1- npm install typings --global

    2 - 在 typings/index.d.ts 上输入以下代码:

        interface Window {
           plugins: any;
        } 
    

    3 - 然后在页面或组件内按以下方式使用窗口:

      constructor(platform: Platform) {
    platform.ready().then(() => {
    
    
     var blabla = window['cordova_plugin_that_was_installed'].function();
    
       });
     }}
    

    【讨论】:

      猜你喜欢
      • 2018-02-17
      • 2017-11-12
      • 2016-11-02
      • 2018-04-10
      • 2016-12-15
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多