0

I wanted to use cordova barcode/qrcode scanner plugin in my angular 7 project.I did a bit of research and got only demos for ionic app.I'm really confused on how to proceed further.How to integrate it in my application?

I have created a cordova application and integrated it with my angular app.It is working fine.But now when i'm trying to use plugins like barcode scanner i'm getting error

cordova plugin add phonegap-plugin-barcodescanner

and then added this line in index.html in angular app

<script type="text/javascript" src="cordova.js"></script>

I'm geting error in app.ts file the cordova does not exist

aeshna Kashyap
  • 135
  • 2
  • 12
  • Please show us some example what you have tried. Usually you need to add the plugin to your cordova app. If you use TypeScript then find the appropriate .d.ts file for the plugin definitions. If you look into the .d.ts file you should be able to figure it out how to call it. – gpro Feb 28 '19 at 09:54
  • In my app,i have to give a property for barcode scanning.Like in this link,ionic is directly using covrdova plugin to make a barcode scanner app https://www.djamware.com/post/59bb219f80aca768e4d2b13e/example-of-ionic-3-angular-4-cordova-barcode-and-qr-code-scanner – aeshna Kashyap Feb 28 '19 at 09:57
  • If you could update your question with details what have you tried it would be easier to help. You could tell us where did you stack with the integration. – gpro Feb 28 '19 at 10:08
  • I have not started with the integration..whatever articles i read used it in ionic application.They installed it using ionic.I also found ngCordova but it is used with angular js – aeshna Kashyap Feb 28 '19 at 10:10
  • I see. So your confusion is that you want cordova plugin for your cordova app, but only found ionic. Is that correct? – gpro Feb 28 '19 at 10:31
  • If you give more detail about the plugin you have chosen I can update my answer to give more help if needed – gpro Feb 28 '19 at 11:03

1 Answers1

0

My recommendation is to search for a plugin in the official site that suites your needs most. Pick one that has got decent description and documentation. The quality ones will guide through the integration with examples.

Update

To get rid of the "does not exist" errors, you will need type definitions if you use TypeScript for cordova and for the plugins as well. For cordova you can install it with npm install --save @types/cordova, but for the chosen plugin you need to find the correct one. You can try to look it up in here. Alternatively you can create your own by hand. You can have a look in type definition in other questions.

gpro
  • 579
  • 8
  • 17
  • I have already created a cordova project and integrated it with my angular application..after that i added the barcode plugin using cordova plugin add phonegap-plugin-barcodescanner and added this line to index.html in angular app.But now when i'm trying to use the function i'm getting error could not find cordova – aeshna Kashyap Feb 28 '19 at 11:38
  • But already my app is wrapped in Cordova and the plugin is installed over there...so what is the use of installing it separately then – aeshna Kashyap Feb 28 '19 at 17:47
  • This is not installing cordova again, but adding type definitions. That is required since TypeScript is a strongly typed language that requires everything to be defined in design time. Hence you need the type definitions for the compiler/intellisense. – gpro Feb 28 '19 at 20:47
  • Even after doing this npm install --save @types/phonegap-plugin-barcodescanner i'm getting error that it is not a module.I got it from here only https://microsoft.github.io/TypeSearch/ – aeshna Kashyap Mar 01 '19 at 05:21
  • Take a look at this page in [angular about TypeScript](https://angular.io/guide/typescript-configuration#typescript-configuration). Alternatively if you can provide some code snippets and the exact error maybe we could move further. – gpro Mar 01 '19 at 10:07