I'm building a cordova application using ionic framework. This application need the ability to generate a QRcode based on the given text. I found http://davidshimjs.github.io/qrcodejs/ as a solution. But I could not implement this in my ionic application. I need some example for this task, implemented by qrcodejs, or any other libraries.Thanks!
Steps to follow to implement Ionic 4 QR code scanner example As we can see in the above output, The button will display 'START SCAN'. After click on 'START SCAN' button, We are calling our method scanQR(). This will call the plugin function scan() which will return the text inside of the QR Code successfully.
Neither angular-qr nor angular-qrcode worked for me, so I ended up rolling my own directive real quick, based on Shim Sangmin's QRCode generator library:
<!-- index.html -->
<script src="lib/qrcode.js/qrcode.js"></script>
-
// directives.js
.directive('qrcode', function($interpolate) {
return {
restrict: 'E',
link: function($scope, $element, $attrs) {
var options = {
text: '',
width: 128,
height: 128,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: 'H'
};
Object.keys(options).forEach(function(key) {
options[key] = $interpolate($attrs[key] || '')($scope) || options[key];
});
options.correctLevel = QRCode.CorrectLevel[options.correctLevel];
new QRCode($element[0], options);
}
};
});
Then use it like so:
<qrcode text="{{something.on.scope}}" color-bright="#ff0000"></qrcode>
<!-- or width, height, color-dark, correct-level -->
Edit: Check it out on JSFiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With