Comments (6)
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.
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.
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.
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.
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.
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)
- Copy QRCode with CTRL+C HOT 2
- not displaying QR code HOT 3
- "qrcode" global naming has conflict with another library which scans qrcode HOT 1
- qrcode is not defined HOT 5
- qrcode will not be generated when 'data' string is too long
- Not see nothing HOT 2
- Wrong qrcode-generator version in bower.json HOT 5
- Download qr code with unique name HOT 1
- url too long HOT 1
- Download is not working on MS Edge HOT 1
- How to print on a device HOT 1
- angularjs bower HOT 2
- Printing issues HOT 2
- qrcode is not defined HOT 2
- Error not working HOT 1
- not an angular project HOT 1
- simply its an html code HOT 1
- Demo not working HOT 2
- bower-qrcode-generator has invalid git url, sometimes it does not work. HOT 2
- How to set size of QR code with higher version number (module)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-qrcode.