我正在尝试扫描文档以获取数据。我正在使用Zxing扫描仪,我得到了错误和相机电源关闭。有一些类似的停顿,但答案对我没有帮助。
我的代码:
import { Component } from '@angular/core';
@Component({
selector: 'app-scanner',
templateUrl: './scanner.component.html',
styleUrls: ['./scanner.component.css']
})
export class ScannerComponent {
constructor() { }
camerasNotFound(e: Event) {
// Display an alert modal here
}
cameraFound(e: Event) {
// Log to see if the camera was found
}
onScanSuccess(result: string) {
console.log(result);
}
scanSuccessHandler(e: Event): void {
}
}
模板是:
<zxing-scanner
#scanner
[formats]="['QR_CODE', 'EAN_13']"
(camerasFound)="cameraFound($event)"
(camerasNotFound)="camerasNotFound($event)"
(scanSuccess)="scanSuccessHandler($event)"
>
</zxing-scanner>
我在这个链接中做了如下操作:https://github.com/zxing-js/ngx-scanner/wiki/Getting-Started
您必须确保安装最新或相同版本的浏览器&库
"zxing/浏览器":"0.0.9";,"zxing/库":"0.18.6〃;,
试试这个
npm i @zxing/browser@0.0.9 --save --legacy-peer-deps
npm i @zxing/library@0.18.6 --save --legacy-peer-deps
npm i @zxing/ngx-scanner@3.2.0 --save --legacy-peer-deps