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

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

srcapp outesa-demoa-demo.module.ts

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

...

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

使用方法

srcapp outesa-demoprintprint.component.ts

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

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

srcapp outesa-demoa-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了

原文地址:https://www.cnblogs.com/sugartang/p/15138606.html