1、在項目根目錄安裝依賴
npm install --save qrcode
2、在typings.d.ts文件裏定義變量
declare var QRCode: any ;
3、html
<!--二維碼 S-->
<div class="code-img">
<div id="qrcode"></div>
</div>
<!--二維碼 E-->
4、css
#qrcode{
width: 180px;
height: 180px;
margin: 10px auto;
}
5、ts
ngAfterViewInit() {
//生成二維碼
var qrcode = new QRCode(document.getElementById("qrcode"), {
width: 180,
height: 180
});
qrcode.makeCode('http://www.kekedj.com');
}