angular2-qrcode (转)

插件选择

angular2-qrcode

npm install angular2-qrcode --save
c
npm install angular2-qrcode --save

参考github

https://github.com/SuperiorJT/angular2-qrcode

使用方法

  1. app.module中引入插件模块
    //src/app/app.module.ts
    //第三方插件模块
    import { QRCodeModule } from 'angular2-qrcode';
  2. 模板文件中以指令(directive)方式调用
    <ion-header>
     <ion-navbar>
         <ion-title text-center>二维码</ion-title>
     </ion-navbar>
    </ion-header>
    <ion-content padding>
     <ion-card>
         <ion-card-header class="text-c">
             <dl class="wqcover">
                 <dt class="font-red">{{storeUserName}}</dt>
                 <dd class="m-n font-n font-light">门店:{{storeName}}</dd>
                 <dd class="m-n font-n font-light">所属供应商:{{storeUserCompany}}</dd>
             </dl>
         </ion-card-header>
         <ion-card-content>
             <div>
                 //此处就是二维码展示部分
                 //如果有变量就这样写: [value]="'用户名:'+storeUserName"
                 <qr-code [value]="'All QR Code data goes here!'"></qr-code>
             </div>
             <p class="text-c font-n font-light">扫一扫上面的二维码图案,办理业务</p>
         </ion-card-content>
     </ion-card>
    </ion-content>

注意事项

  1. 模块在app.module中引入后就可以直接使用了,不需要将其加入declarations中,也不用在组建中引入
  2. 不要像官方文档中那样在组件的@component装饰器中加入directives元属性,会报错的
  3. 以上两点及实现效果基于我使用的版本,下面给出package.json参考
{
  "name": "ionic-app-base",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/compiler-cli": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/platform-server": "2.2.1",
    "@ionic/storage": "1.1.7",
    "angular2-qrcode": "^2.0.0",  //qrcode插件版本
    "ionic-angular": "2.0.0-rc.4",
    "ionic-native": "2.2.11",
    "ionicons": "3.0.0",
    "qrcode-generator-ts": "0.0.4",
    "rxjs": "5.0.0-beta.12",
    "ts-md5": "^1.2.0",
    "zone.js": "0.6.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.47",
    "typescript": "2.1.6"
  }
}

效果展示


二维码

可选参数

AttributeTypeDefaultDescription
valueString''Your data string (需要转换成二维码的字符串)
sizeNumber128This is the height/width of your QR Code component(图片尺寸)
levelString'M'QR Correction level ('L', 'M', 'Q', 'H')(感觉好像是图片颗粒度)
typeNumber4Buffer size for data string
backgroundString'white'The color for the background
backgroundAlphaNumber1.0The opacity of the background
foregroundString'black'The color for the foreground
foregroundAlphaNumber1.0The opacity of the foreground
mimeString'image/png'The mime type for the output image
paddingNumbernullThe padding around the QR Code
canvasBooleanfalseWill output a canvas element if true(输出canvas)



作者:小pxu
链接:http://www.jianshu.com/p/418d768c1c2c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

转载于:https://www.cnblogs.com/richard1015/p/7574597.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值