首页 > 解决方案 > 如何生成二维码列表?

问题描述

我需要在 Angular 中使用 HTTP GET 调用后生成一个二维码列表angularx-qrcode (10.0.11)。我无法理解如何将我的客户代码 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;
    });
  }

}

这没用。我怎样才能实现我想要的行为?

标签: angularqr-code

解决方案


解决方案非常简单:

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

推荐阅读