如何生成二维码列表?

时间:2020-12-26 14:23:00

标签: angular qr-code

我需要在 Angular 中使用 angularx-qrcode (10.0.11) 进行 HTTP GET 调用后生成一个二维码列表。我无法理解如何将我的客户代码 var 传递给 <qrcode/> 元素。

这是我的简单实现:

<h3>Customers QR</h3>
<li *ngFor="let customer of customers">
    <qrcode [qrdata]="{{customer.code}}" [width]="256" [errorCorrectionLevel]="'M'"></qrcode>
</li>
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { environment } from 'src/environments/environment';

@Component({
  selector: 'app-customers-qr',
  templateUrl: './customers-qr.component.html',
  styleUrls: ['./customers-qr.component.scss']
})
export class CustomersQrComponent implements OnInit {
  customers: any[];

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.http.get<any>(`${environment.baseUrl}/customers`).subscribe((customers) => {
      // Assign articles to table
      this.customers = customers;
    });
  }

}

它不起作用。如何实现我想要的行为?

1 个答案:

答案 0 :(得分:0)

解决方案非常简单:

<qrcode [qrdata]="customer.code" [width]="128" [errorCorrectionLevel]="'M'"></qrcode>