[英]error TS2304: Cannot find name 'QRScanner'
I referring https://www.npmjs.com/package/cordova-plugin-qrscanner and trying to create a QR Scan function in my mobile app.我参考https://www.npmjs.com/package/cordova-plugin-qrscanner并尝试在我的移动应用程序中创建 QR 扫描 function。
So for first steps, I am creating the following code in my ts file:因此,对于第一步,我在我的 ts 文件中创建以下代码:
function onDone(err, status){
if (err) {
// here we can handle errors and clean up any loose ends.
console.error(err);
}
if (status.authorized) {
// W00t, you have camera access and the scanner is initialized.
// QRscanner.show() should feel very fast.
} else if (status.denied) {
// The video preview will remain black, and scanning is disabled. We can
// try to ask the user to change their mind, but we'll have to send them
// to their device settings with `QRScanner.openSettings()`.
} else {
// we didn't get permission, but we didn't get permanently denied. (On
// Android, a denial isn't permanent unless the user checks the "Don't
// ask again" box.) We can ask again at the next relevant opportunity.
}
}
QRScanner.prepare(onDone);
However, I am getting error when I am trying to ng build.但是,当我尝试构建时出现错误。
TS2304: Cannot find name 'QRScanner'
TS2304:找不到名称“QRScanner”
The following is my version:以下是我的版本:
And my cordova-plugin-qrscanner version in package.json is:而我在 package.json 中的 cordova-plugin-qrscanner 版本是:
"@types/cordova-plugin-qrscanner": "^1.0.31",
"cordova-plugin-qrscanner": "^3.0.1",
Good day,再会,
I found the solution and the following is some of my understanding.我找到了解决方案,以下是我的一些理解。 This code is work for older version of angular. I am using angular 10, thus, need to define the
QRScanner
object first.此代码适用于旧版本的 angular。我使用的是 angular 10,因此,需要先定义
QRScanner
object。 Which is:这是:
declare var QRScanner: any
; declare var QRScanner: any
;
Or use ( < any > window).QRScanner
to get access of the QRScanner plugin.或者使用
( < any > window).QRScanner
来访问 QRScanner 插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.