【问题标题】:how to use plugin in cordova/ionic framework如何在cordova/ionic 框架中使用插件
【发布时间】:2015-04-08 22:48:35
【问题描述】:

我想导入一个示例插件在 cordova/ionic 中测试,我试试这个

$ cordova plugin add org.apache.cordova.device

现在在我的 index.html 中我使用此代码

var model = device.model;
document.write(device.model);

然后

cd myionicApp
cordova emulate

但它不起作用,有人可以帮助我吗? 还安装了 cordova CLI 和 Cordova Plugman 和 Ionic Framework

【问题讨论】:

    标签: cordova ionic-framework cordova-plugins ionic


    【解决方案1】:

    添加

    var model = device.model;
    document.write(device.model);
    

    document.addEventListener("deviceready", success, error);
    function success(){
        var model = device.model;
        document.write(device.model);
    };
    function error(){
    
    };
    

    在您的情况下,它不起作用,因为在设备准备好之前不会调用插件。所以我们需要添加设备就绪监听器。然后只会调用任何插件。

    问候。

    【讨论】:

      【解决方案2】:

      请参考:

      <html>
        <head>
          <title>Device Properties Example</title>
      
          <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
          <script type="text/javascript" charset="utf-8">
      
          // Wait for device API libraries to load
          //
          document.addEventListener("deviceready", onDeviceReady, false);
      
          // device APIs are available
          //
          function onDeviceReady() {
              var element = document.getElementById('deviceProperties');
              element.innerHTML = 'Device Model: '    + device.model    + '<br />' +
                                  'Device Cordova: '  + device.cordova  + '<br />' +
                                  'Device Platform: ' + device.platform + '<br />' +
                                  'Device UUID: '     + device.uuid     + '<br />' +
                                  'Device Version: '  + device.version  + '<br />';
          }
      
          </script>
         </head>
         <body>
           <p id="deviceProperties">Loading device properties...</p>
         </body>
         </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-12-16
        • 1970-01-01
        • 2020-06-11
        • 2016-11-02
        • 2016-12-15
        • 1970-01-01
        • 2018-06-06
        相关资源
        最近更新 更多