【问题标题】:ionic/cordova cannot create pluginionic/cordova 无法创建插件
【发布时间】:2016-02-02 10:16:01
【问题描述】:

我在 ionic 框架中创建自己的插件时遇到问题。

这是我的 plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="org.apache.cordova.hid" version="0.0.1">
  <name>Hid</name>
  <description>Cordova HID USB Plugin</description>
  <license>Apache 2.0</license>
  <keywords>cordova,hid</keywords>
  <js-module src="www/hid.js" name="hid">
    <clobbers target="hid" />
  </js-module>
</plugin>

这是我的 hid.js 文件,其中包含测试代码:

var exec = require('cordova/exec');

var hid = {
  testFunc : function(callback) {
    callback('echo echo');
  }
}
module.exports = hid;

我使用 add 将插件安装到项目中:

$ ionic plugin add ./hid-plugin
Updated the hooks directory to have execute permissions
Saving plugin to package.json file

然后它出现在我的插件文件夹中的项目中。

这是我的 controllers.js:

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope) {})

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);

  // HERE IS THE TESTFUNC
  hid.testFunc(function(echoValue) {
    alert(echoValue);
  });
});

这会导致错误:

ionic.bundle.js:25642 ReferenceError: hid is not defined
    at new <anonymous> (http://localhost:8100/js/controllers.js:23:5)
    at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17)
    at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17770:27)
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:22326:28
    at self.appendViewElement (http://localhost:8100/lib/ionic/js/ionic.bundle.js:56883:24)
    at Object.switcher.render (http://localhost:8100/lib/ionic/js/ionic.bundle.js:54995:41)
    at Object.switcher.init (http://localhost:8100/lib/ionic/js/ionic.bundle.js:54915:20)
    at self.render (http://localhost:8100/lib/ionic/js/ionic.bundle.js:56743:14)
    at self.register (http://localhost:8100/lib/ionic/js/ionic.bundle.js:56701:10)
    at updateView (http://localhost:8100/lib/ionic/js/ionic.bundle.js:62357:23) <ion-nav-view name="tab-chats" class="view-container tab-content" nav-view="active" nav-view-transition="android">

我几乎尝试了所有方法:

  • 在没有隐藏包装对象的 hid.js 中创建函数
  • 将隐藏对象放入ChatDetailCtrl的参数中
  • 使用 $hid 代替 hid

但没有积极的结果。

你能指出我错过了什么或做错了什么吗?

【问题讨论】:

    标签: javascript cordova plugins ionic-framework


    【解决方案1】:
    1. 将你的js文件导入index.html
    2. 查看并检查您的 cordova_plugins.js 文件(您可以在此处更新)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      相关资源
      最近更新 更多