angular2-qrcode 引用报错 error NG8001: 'qr-code' is not a known element:

error NG8001: ‘qr-code‘ is not a known element:

解决方案

假如你的组件模块叫做a-demo.module,你的组件叫做print.component.ts

检查使用方法,在当前组件的模块里引入

src\app\routes\a-demo\a-demo.module.ts

import { NgModule } from ‘@angular/core‘;
import { QRCodeModule } from ‘angular2-qrcode‘;

...

@NgModule({
    imports: [
        QRCodeModule,
        ...
    ]
})

使用方法

src\app\routes\a-demo\print\print.component.ts

<div>
    <qr-code [value]="‘All QR Code data goes here!‘" [size]="150"></qr-code>
</div>

如果还报错,检查你的组件是否在当前模块的路由以及模块都进行注册了

src\app\routes\a-demo\a-demo-routing.module.ts

import { NgModule, Type } from ‘@angular/core‘;
import { QRCodeModule } from ‘angular2-qrcode‘;

import { ADemoRoutingModule } from ‘./a-demo-routing.module‘;
import { PrintComponent } from ‘./print/print.component‘;  // 重点观察这一个代码,你有没有写

const COMPONENTS: Array<Type<void>> = [PrintComponent]; // 重点观察这一个代码,你有没有写

@NgModule({
  imports: [QRCodeModule, ADemoRoutingModule],
  declarations: COMPONENTS
})
export class ADemoModule { }

OK了

angular2-qrcode 引用报错 error NG8001: 'qr-code' is not a known element:

上一篇:JUnit5 快速入门指南


下一篇:178. 分数排名