Reputation: 11
I'm using a cordova plugin from github, not available in ionic native.
I have problem. How to use non ionic-native plugins in Ionic 2 ?
I try :
declare var myPlugin: any;
myPlugin.doSomething(...)
and other forum solutions
but I have error :
ReferenceError: myPlugin is not defined
at new HomePage (http://localhost:8100/build/main.js:18762:9)
My config :
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
Same problem : Working with non ionic-native plugins in Ionic 2
Upvotes: 0
Views: 1055
Reputation: 5700
Please try like this :
First import plugin or library as :
import plugin from 'plugin-name' ;
And then use :
plugin.functionName();
Upvotes: 0
Reputation: 29635
Your problem is that in plugin.xml clobbers
is set as window.plugins.myplugin
.
This makes window the global object and you have to declare:
declare var window: any;
and functions called as:
window.plugins.myPlugin.pluginInitialize()
or if this is your custom made plugin, you could make clobbers object as myPlugin
Upvotes: 1
Reputation: 5819
Few things to look:
Refer the below thread which might be of some help on editing your plugin.xml file.
https://forum.ionicframework.com/t/how-to-use-non-native-plugins-on-ionic-2/63936/17
Upvotes: 1