I am having the same difficulty in understanding how to use custom plugins cordova. The example in the documentation is a bit confusing, do not say where or by using the plugin, lack an example.
I never had a problem with cordova custom plugin ( ZPL printer over tcpip) for ionic2@beta.19, however when I upgrade to beta 37 it does fail. the custom plugin that i am using cordova.plugins.zebra.tcp.printer.ZplOverTcpIp.print(ip, bclables) doesn’t work.
on ionic server start it throws an TypeScript error Error TS2304: Cannot find name ‘cordova’.
because of this error in beta.37 doesn’t load the ionic app at all and just show blank ionic lab page… I did not had problem with .19
i tried (window).CustomPlugin.method() and window.plugin.myPlugin.myMethod()
nothing works. my App suppose to go prod. Its on hold because of this issue… any advise would be great help.
Referring to stirumala’s question.
If we have to add our plugin to ionic native ,we understand we have to submit PR.
How much time it takes for PR to add external plugin into ionic-native?
Basically what’s happening, TS doesn’t know about your code, so it wont build because it thinks you’re giving it invalid code. You need to let the compiler know about your plugin, and add it to typings
interface Navigator {
// we let the main navigator object know that it should have camera on it, and camera is a type of Camera.
// for you this would be your plugins main object
camera: Camera;
}
Then we build out the methods for camera.
// Here we're describing the getPicture method
interface Camera {
// getPicture has three arguments,
// a success callback, error callback, and any options
getPicture(
cameraSuccess: (data: string) => void,
cameraError: (message: string) => void,
cameraOptions?: CameraOptions): void;
}
So this would be your plugin’s method, so something like customPrinter.print() followed by the success and error callback (or how ever you set it up)
@Mike for our custom plugin ZPlPrint we have ZplOverTcpIp.js file created and if we create interface like you suggested ,imagine ZplOverTcpIp.d.ts and put it where asll .d.ts files are there
We are not sure how we can map that ZplOverTcpIp.d.ts to the actual code. Are we missing any step?
Whatever the interface we write for print in ts file , how it will interact with our custom plugin js file code as shown below.
our custom plugin js file.