How to use custom plugin

@mhartington

Please find the changes that I made in the code

this is how i am calling in my current code to invoke the printer after the suggested changes
this.platform.ready().then(() => {

     ZPLPrinter.print(ip, bclables,
      function (success) {
        alert(success);
      }
      ,
      function (fail) {
        alert('fail');
      });
     
  });

however I still see the error Error TS2304: Cannot find name ‘ZPLPrinter’.
Did I miss anything else ?

please find the sample zpl poc code at https://github.com/stirumala76/zpl-printer-poc/blob/master/MyIonic2Project/

So there were a few things missing in your example project.

I ended up forking the repo, and sending a PR your way.

The changes are pretty minimal, but the overall idea is that you declare the module in you class, the give it a type that matches your definition file.

declare var ZPLPrinter: ZPLPrinter;

Thanks @mike that was a great help from you. Will test it on ios and andriod and let you know if we have any issues.

@mhartington mike We got the following issue…please find the error below.

image

@mhartington I see some code changes in github,is the issue resolved?

Hi @lthh89vt,

I am new to Ionic,

I’m using Ionic2 with typescript, and I didn’t manage to use this plugin : https://github.com/card-io/card.io-Cordova-Plugin

Can you share how could you hack this?
What need to included in the source code?

Thanks,
Punleu

hi @stirumala,

Have you found solution for this?
I am having the same issue with https://ionicframework.com/docs/v2/native/cardio/

I’ve been searching for few days. I am still not able to use this plugin in Ionic2.

Thanks,
Punleu

Are you testing this in chrome test lab or phone…?

haven’t tried but these are my initial thoughts for you in case if you haven’t done these

  1. create sample poc
  2. configured the pluigin in your ionic app and put an alert message in plugin code to see the card reader value as given in the doc, make sure u install the pluin in ur app
    https://ionicframework.com/docs/v2/native/cardio/
  3. deploy on phone android or IOS , I believe this plugin doesn’t work test lab, should deploy apk - android and ipa on ios .
  4. hook up the card reader scan to your phone.
    image
  5. you can debug the app using android phone with chrome debug
    https://developers.google.com/web/tools/chrome-devtools/remote-debugging/

good luck!!

Hi Stirumala,

I got this fixed already. It’s the issue with Ionic View.
The solution is install the APK on the device.

Thanks,
Punleu

hi Mhartington,
Cant you make any video demonstrating from scratch such that i can understand as i am a new bye to this development environment

Thanks
Vishu

Hello if somen here got the error:

error TS2339: Property 'plugins' does not exist on type 'Window'.

Try like this:

(<any>window).plugins.somePlugin.doSomething();

declare let cordova: any;

this.platform.ready().then(() => {
var success = function(result) {
alert(JSON.stringify(result, undefined, 2));
}
var failure = function(result) {
alert(JSON.stringify(result, undefined, 2));
}

	cordova.plugins.pluginname.method(message,success,failure);

});

Once you added plugin to your project, go to the file (.ts) in which you want to use the plugin.
Then follow the steps given below

declare var yourplugin;
yourplugin.doSomething()

This helps me to call the method doSomething() in yourplugin.

1 Like

Excuse me, I’m really new here,where is the name of the file or the directory that I need to write the import section.