私はすでにcordovaプラグインを作成しており、すでにIonic 1で使用されています。それから私はIonic 2でそれを使用しようとしましたが、プラグインの呼び出し方法はわかりません。私はhereの手順に従います。そして、これは私がやったことです:イオン2:カスタムビルドの使い方Cordova Plugin
plugin.xmlの
<name>myPlugin</name>
<js-module src="www/myPlugin.js" name="myPlugin">
<clobbers target="myPlugin" />
</js-module>
myPlugin.js
module.exports = {
myFunction: function (success, failure) {
cordova.exec(success, failure, "myPlugin", "myFunction", []);
}
};
ハローionic.ts
import { Component } from '@angular/core';
declare var cordova: any;
@Component({
selector: 'page-hello-ionic',
templateUrl: 'hello-ionic.html'
})
export class HelloIonicPage {
constructor() {
}
click() {
if (typeof cordova !== 'undefined') {
cordova.plugins.myPlugin.myFunction();
}
}
}
hello-ionic.ts
にエラー"Undefined myFunction"
が返されます。 ご協力いただきありがとうございます。私は複数のカスタムプラグインを作成するには、このチュートリアルを踏襲しており、それらはIonic2で正常に動作している
https://taco.visualstudio.com/en-us/docs/createplugintutorial/
:
haventはカスタムプラグインを作成しましたが、プラグインコードを 'Platform.ready()'にカプセル化する必要があります –
@suraj既に 'Platform.ready()'が追加されていますが、エラー:未定義のプロパティ 'myFunction'を読み取ることはできません。 –
宣言を使用しようとしましたか?var myPlugin:any; codeova.plugins.myPlugin.myFunction()の代わりにmyPlugin.myFunction()を使用します。 – AishApp