我在离子框架中创建自己的插件时遇到问题。
这是我的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
然后它出现在我的项目中的plugins文件夹中。
这是我的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">
我几乎尝试了一切:
但没有积极的结果。
你能指出我错过了什么或做错了吗?
答案 0 :(得分:0)