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

时间:2019-04-08 20:12:01

标签: npm jhipster qr-code angular7

我已经在这个问题上停留了将近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 Code的我的应用程序中,它不会显示QR Code,但是区别在于它也不会显示任何控制台错误。这与我尝试生成的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"
  }
}

在这一点上,我不知道该怎么办。预先感谢。

2 个答案:

答案 0 :(得分:1)

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

尝试安装

npm install @techiediaries/ngx-qrcode --save

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

答案 1 :(得分:0)

我有同样的错误。

已弃用Manab said。因此,请使用[value]而不是[qrc-value]:

memoryStream