sup*_*_89 6 qr-code cordova ionic-framework
我正在使用离子框架构建cordova应用程序.该应用程序需要能够基于给定文本生成QRcode.我找到了http://davidshimjs.github.io/qrcodejs/作为解决方案.但我无法在我的离子应用程序中实现这一点.我需要一些这个任务的例子,由qrcodejs或任何其他库实现.谢谢!
angular-qr和angular-qrcode都没有为我工作,所以我最终根据Shim Sangmin的QRCode生成器库快速滚动我自己的指令:
<!-- index.html -->
<script src="lib/qrcode.js/qrcode.js"></script>
Run Code Online (Sandbox Code Playgroud)
-
// 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);
}
};
});
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
<qrcode text="{{something.on.scope}}" color-bright="#ff0000"></qrcode>
<!-- or width, height, color-dark, correct-level -->
Run Code Online (Sandbox Code Playgroud)
编辑:在JSFiddle上查看它.
因此,您需要的是一个 Angular 模块,大多数时候您必须创建自己的指令、模块或 Angular 代码来集成 JavaScript 插件。但有人已经这样做了,我会看看http://ngmodules.org/modules/angular-qr应该是你正在寻找的。请参阅演示:http://janantala.github.io/angular-qr/demo/
| 归档时间: |
|
| 查看次数: |
14363 次 |
| 最近记录: |