Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic cordova - QRcode generate example

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!

like image 376
supper aban_89 Avatar asked Jun 11 '15 19:06

supper aban_89


People also ask

How do I scan QR codes in ionic 4?

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.


1 Answers

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.

like image 165
Michael Jess Avatar answered Sep 28 '22 02:09

Michael Jess