Details link Address: http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-2-cordovabarcodescanner/
This is a use to scan the QR code of the Cordova plug-in, when doing the project want to achieve similar sweep sweep function, think of the Cordova $cordovabarcodescanner plug-in, with a very small amount of code can be achieved, the following to see the specific implementation steps:
- Scan two-dimensional code:
1, first need to have a simple project, and then enter the command line to add plug-in commands:
Cordova Plugin Add Https://github.com/phonegap/phonegap-plugin-barcodescanner.git |
2, the code in the HTML below, is to write a Ng-click event to trigger this function:
<div class= "card" > <div class= "Item" > <button class= "button Button-block button-positive" Ng-clic K= "Scanstart ()" > <i class= "icon Ion-qr-scanner" ></i> Scan now </button> </div>< ;/div><div class= "card" > <div class= "Item Item-divider" >scan results</div> <div class= "item Item-text-wrap "> {barcodedata}} </div></div> |
3, the code in JS is as follows, this code is written in the corresponding controller and depends on ' $cordovaBarcodeScanner ', remember to rely on ' Ngcordova ' in App.js,:
$scope. Scanstart = function () {$cordovaBarcodeScanner. Scan (). Then (function (barcodedata) {alert (bar CodeData); $scope. barcodedata = Barcodedata; success!
Barcode data is here}, function (Error) {alert (' failed ')//An error occurred}); |
4, this can run to the phone to scan, but after the implementation of the scanning function there is a problem, if it is similar to the scan, but also need to generate their own QR code, this I read the official document of the next Ngcordova (http://ngcordova.com/ docs/plugins/barcodescanner/), the document has this function code, but now seems to be imperfect, so not use!! Therefore, I have found some ways to generate two-dimensional code with JS.
- Generate two-dimensional code:
1, need to download qrcode.js and jquery.js, you can go to the Internet to find a lot, here to provide a place to download (https://github.com/davidshimjs/qrcodejs/), downloaded to the local after the introduction to the project
2, the relevant HTML code is as follows:
<div id= "QRCode" ></div> |
3, the relevant JS code is as follows:
var qrcode = new QRCode (document.getElementById ("QRCode"), { width:96,//set width height height:96}); Qrcode.makecode (" Http://www.baidu.com "); |
Come and try it, this will generate a unique QR code, but I still look forward to Codova official plug-in Ah, I hope a little earlier can use!
Cordova each plug-in use Introduction series (a)-$cordovaSms send SMS