2017-02-15 136 views
0

我正在使用github上的cordova插件,不適用於離子原生。在離子2中使用非離子原生插件2

我有問題。如何在離子2中使用非離子原生插件?

我嘗試:

declare var myPlugin: any; 

myPlugin.doSomething(...) 

和其他論壇的解決方案

但我有錯誤:

ReferenceError: myPlugin is not defined 
at new HomePage (http://localhost:8100/build/main.js:18762:9) 

我的配置:

Ionic Framework: ^2.0.0-rc.3 
Ionic Native: ^2.2.3 
Ionic App Scripts: 1.0.0 
Angular Core: 2.2.1 
Angular Compiler CLI: 2.2.1 
Node: 6.9.5 
OS Platform: Windows 10 
Navigator Platform: Win32 
cordova 6.5.0 

同樣的問題: Working with non ionic-native plugins in Ionic 2

+0

你可以添加一個鏈接到你正在嘗試使用的插件嗎? 正如您提供的鏈接中所建議的那樣,您是否嘗試登錄'cordova'來查看插件是否在那裏? –

+0

你正在嘗試在一個設備或離子發球? –

+0

在離子發射,測試初始化​​功能。我會嘗試設備。 – ghot

回答

1

很少有東西看:

  • 驗證,如果你的插件條目存在於plugin.xml中和的package.json文件?如果不是,您可能需要添加一個條目,如下例所示。
  • 僅當平臺準備就緒時才使用插件。
  • 在真實設備上測試您的應用程序。
  • 使用「ionic add」代替「cordova add」添加新的插件。

請參考下面的線程,這可能對編輯plugin.xml文件有幫助。

https://forum.ionicframework.com/t/how-to-use-non-native-plugins-on-ionic-2/63936/17

1

你的問題是,在plugin.xml中clobbers設置爲window.plugins.myplugin。 這使得窗口全局對象,你必須聲明:

declare var window: any; 

和功能稱爲:

window.plugins.myPlugin.pluginInitialize() 

,或者如果這是你定製的插件,你可以做則會覆蓋對象爲myPlugin