Reputation: 1
I have created custom Cordova plugin. I want to use that plugin into ionic2 that uses typescript and angular 2. I am able to add the plugin into ionic 2 project. But call of methods defined in plugin .Java classes does't work. If class imported in following way: import Hello from '@ionic-native/hello';
It gives an error "Cannot find module '@ionic-native/hello'". Please let me know the way to use plugin in ionic 2.
Thanks,
Upvotes: 0
Views: 747
Reputation: 7507
Your own plugin is not part of ionic-native
so you cannot import it from ionic-native
. In your plugin.xml
you should have a js-module
element which looks something like this:
<js-module src="www/yourplugin.js" name="yourplugin">
<clobbers target="window.plugins.yourplugin"/>
</js-module>
If you want to use this plugin you have to tell typescript that yourplugin
will exist at runtime. You do this with this line of code:
declare var yourplugin;
You have to add this line in every typescript class where you want to use your plugin at the same level as your imports.
The documentation for js-module
and clobbers
is available here.
Upvotes: 2