You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14安装ngx-qrcode2遇依赖冲突,求推荐替代二维码库

适用于Angular 14的二维码生成库推荐

ngx-qrcode2@9.0.0的peer依赖限制在Angular 6-10版本,且对tslib的版本要求和你当前项目冲突,确实没法在Angular 14里正常使用。下面推荐几个适配Angular 14的替代库:

  • ngx-qrcode-styling
    维护活跃,完全支持Angular 14+,还支持自定义二维码样式(比如颜色、logo、圆角)。
    安装命令:npm install ngx-qrcode-styling --save
    基本用法:在模块中导入NgxQrcodeStylingModule,模板中直接使用组件:

    <ngx-qrcode-styling
      [data]="'需要生成二维码的内容'"
      [width]="200"
      [height]="200"
      [image]="'./assets/logo.png'"
    ></ngx-qrcode-styling>
    
  • angularx-qrcode
    专为Angular生态更新的二维码库,支持最新Angular版本,配置选项丰富(大小、纠错级别、颜色等)。
    安装命令:npm install angularx-qrcode --save
    基本用法:模块导入QRCodeModule,模板中使用:

    <qrcode
      [value]="'你的文本内容'"
      [width]="150"
      [colorDark]="'#000000'"
      [colorLight]="'#ffffff'"
    ></qrcode>
    
  • qrcode-generator
    轻量纯JS库,没有Angular特定封装,灵活性极高,适合需要手动控制渲染逻辑的场景。
    安装命令:npm install qrcode-generator --save
    基本用法:在组件中导入后生成二维码数据,再渲染到canvas或img标签:

    import * as qrcode from 'qrcode-generator';
    
    // 生成二维码
    const qr = qrcode(4, 'L');
    qr.addData('要编码的内容');
    qr.make();
    // 获取SVG或HTML格式的代码插入到页面
    const qrHtml = qr.createImgTag(4, 2);
    

选择时优先查看库的peer依赖声明,确认支持Angular 14,同时尽量选近期有更新的包,避免后续出现兼容问题。

内容的提问来源于stack exchange,提问作者Thomas Geiger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 08:26:10