为什么我的Ngx-qrcode2无法在Angular中生成QR码?

问题描述 投票:1回答:2

我已经在这个问题上停留了将近3天。因此,我目前正在尝试在页面上显示一个QR码,该页面会将您带到URL。为此,我正在使用ngx-qrcode2

到目前为止,我已经尝试过运行npm install ngx-qrcode2 --save。然后,我遵循了本教程:https://www.youtube.com/watch?v=4bsrqHcb-hQ,甚至生成了另一个有角度的应用程序,并且完全按照他的操作。它仍然不起作用。运行它之后,我的控制台显示以下错误:

Uncaught Error: Template parse errors:
Can't bind to 'qrc-value' since it isn't a known property of 'ngx-qr-code'.

而且,在我一直在尝试生成QR码的我自己的应用中,它不会显示QR码,但区别在于它也不会显示任何控制台错误。这与我尝试生成的QR Code应用程序分开。

这是QR Code生成的应用程序中的一些代码:

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'qra-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  value = 'http://www.google.com';
}

app.component.html

<h1>Visit this site.</h1>
<ngx-qr-code qrc-element-type="url" [qrc-value]="value"></ngx-qr-code>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxQRCodeModule } from 'ngx-qrcode2';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxQRCodeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的其他应用程序也具有完全相同的内容。

此外,如果有帮助,这是我的package.json文件。

{
  "name": "qrcode",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "ngx-qrcode2": "0.0.9",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.8",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

目前,我不确定还有什么要做的。预先感谢。

npm jhipster qr-code angular7
2个回答
1
投票

不建议使用npm软件包ngx-qrcode2。请使用@ techiediaries / ngx-qrcode。

尝试安装

npm install @techiediaries/ngx-qrcode --save

这里是更新软件包https://www.npmjs.com/package/@techiediaries/ngx-qrcode的链接


0
投票

我有同样的错误。

如Manab所言,已弃用,因此请使用[value]而不是[qrc-value]

<ngx-qrcode [value]="createdCode"></ngx-qrcode>
© www.soinside.com 2019 - 2024. All rights reserved.