Giter Club home page Giter Club logo

Comments (6)

windbender avatar windbender commented on June 24, 2024

So in kazuhikoarase's code:

        var _dataList = new Array();
...
               _this.addData = function(data) {
            var newData = qr8BitByte(data);
            _dataList.push(newData);
            _dataCache = null;
        };

It does indeed appear that "addData" really is adding data onto whatever is already there. This implies that the "qr"
variable created here:

qr = qrcode(version, correction);

is actually shared amongst all of instances somehow. My Directive-Foo is not strong enough yet to understand why this is the case.

from angular-qrcode.

windbender avatar windbender commented on June 24, 2024

it seems that using a "compile" function won't work because this is essentially looking at the "prerendered" template, and of course the ng-repeat hasn't been repeated in the pre-rendered template.
So the code will need rework to deal work with a "link" function instead.

from angular-qrcode.

windbender avatar windbender commented on June 24, 2024

Ok, so this is not a pull request, because I removed functionality, but this works for me. something good doesn't work with this. so you have to do But ng-repeat does work!!!.

host windbender$ diff qrcode.js qrcode.js.org 
8c8
<   .directive('qrcode', ['$window', function($window){
---
>   .directive('qrcode', ['$timeout', '$window', function($timeout, $window){
32c32
<       link: function(scope, element, attrs, ctrl) {
---
>       compile: function(element, attrs, transclude){
60c60,71
<         if (attrs.text) {
---
>         if (!attrs.text) {
> 
>           return function(scope, element, attrs){
>             transclude(scope, function(clone){
>               $timeout(function(){
>                 var text = clone.text().replace(trim, '');
>                 render(qr, text);
>               });
>             });
>           };
> 
>         } else {

from angular-qrcode.

jaakritso avatar jaakritso commented on June 24, 2024

The @windbender fix did not work for me.

@monospaced is there chance that you'll try to fix it or should I try to find another solution:)

from angular-qrcode.

windbender avatar windbender commented on June 24, 2024

here's my complete code:


$ cat my-qrcode.js 
/*
 * angular-qrcode v1.1.0
 * (c) 2013 Monospaced http://monospaced.com
 * License: MIT
 */

angular.module('monospaced.qrcode', [])
  .directive('qrcode', ['$window', function($window){

    var canvas2D = !!$window.CanvasRenderingContext2D,
        levels = {
          'L': 'Low',
          'M': 'Medium',
          'Q': 'Quartile',
          'H': 'High'
        },
        draw = function(context, qr, modules, tile){
          for (var row = 0; row < modules; row++) {
            for (var col = 0; col < modules; col++) {
              var w = (Math.ceil((col + 1) * tile) - Math.floor(col * tile)),
                  h = (Math.ceil((row + 1) * tile) - Math.floor(row * tile));
              context.fillStyle = qr.isDark(row, col) ? '#000' : '#fff';
              context.fillRect(Math.round(col * tile), Math.round(row * tile), w, h);
            }
          }
        };

    return {
      restrict: 'E',
      template: '<canvas></canvas>',
      transclude: true,
      link: function(scope, element, attrs, ctrl) {
        var domElement = element[0],
            canvas = element.find('canvas')[0],
            version = Math.max(1, Math.min(parseInt(attrs.version, 10), 10)) || 4,
            correction = attrs.errorCorrectionLevel in levels ? attrs.errorCorrectionLevel : 'M',
            trim = /^\s+|\s+$/g,
            qr = qrcode(version, correction);

        qr.make();

        var modules = qr.getModuleCount(),
            size = parseInt(attrs.size, 10) || modules * 2,
            tile = size / modules,
            render = function(qr, text){
              qr.addData(text);
              qr.make();
              if (canvas2D) {
                draw(context, qr, modules, tile);
              } else {
                domElement.innerHTML = qr.createImgTag(tile, 0);
              }
            };

        if (canvas2D) {
          var context = canvas.getContext('2d');
          canvas.width = canvas.height = size;
        }

        if (attrs.text) {

          attrs.$observe('text', function(value){
            var text = value.replace(trim, ''),
                qr = qrcode(version, correction);
            render(qr, text);
          });

        }
      }
    };
  }]);

and in use:

<qrcode error-correction-level="M" version="8"  size="{{cardSize}}" text="{{machine}}/#/locsum/{{location.id}}"></qrcode>

from angular-qrcode.

monospaced avatar monospaced commented on June 24, 2024

Hi all,

Originally, I really liked the simplicity of <qrcode>string</qrcode>, and had been trying to preserve this approach.

But supporting this was making it hard to do basic angular stuff, like observing scope and nesting directives (e.g. this ng-repeat issue).

So now I have changed the design, and the basic usage is <qrcode data="string"></qrcode>: 4060dd5

Hopefully this fixes your problems!

This is a breaking change, so I have update the readme and the bower version.

from angular-qrcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.