我引用https://www.npmjs.com/package/cordova-plugin-qrscanner并尝试在我的移动的应用程序中创建QR扫描功能。
因此,对于第一步,我将在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);
然而,当我尝试ng构建时,我遇到错误。
TS 2304:找不到名称'QRScanner'
以下是我的版本:
- Angular CLI:10.2.3
- 节点:10.16.3
- 操作系统:Linux
- Angular :10.2.5
- npm版本:6.9.0
我的cordova-plugin-qrscanner在package.json中的版本是:
"@types/cordova-plugin-qrscanner": "^1.0.31",
"cordova-plugin-qrscanner": "^3.0.1",
1条答案
按热度按时间4nkexdtk1#
祝你愉快,
我找到了解决方案,下面是我的一些理解。这段代码是为旧版本的angular工作的。我使用的是angular 10,因此,需要首先定义
QRScanner
对象。即:declare var QRScanner: any
;或者使用
( < any > window).QRScanner
访问QRScanner插件。