我正在使用离子框架构建cordova应用程序.该应用程序需要能够基于给定文本生成QRcode.我找到了 http://davidshimjs.github.io/qrcodejs/作为解决方案.但我无法在我的离子应用程序中实现这一点.我
<!-- 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);
}
};
});
然后像这样使用它:
<qrcode text="{{something.on.scope}}" color-bright="#ff0000"></qrcode>
<!-- or width, height, color-dark, correct-level -->
编辑:请在JSFiddle查看.
