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:
First, scan the QR 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-click=" 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> |
$scope .scanstart = function () {$cordovaBarcodeScanner. Scan (). Then (function ( Barcodedata) {alert (barcodedata); $scope. Barcodedata = barcodedata;// success! barcode data is here}, function (Error) {alert (' failure ')// 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.
Second, the generation of 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!
This article is from the "11141997" blog, please be sure to keep this source http://11151997.blog.51cto.com/11141997/1743334
Cordova each plug-in use Introduction series (ii)-$cordovaBarcodeScanner scan two-dimensional code and generate two-dimensional code