【问题标题】:error TS2304: Cannot find name 'QRScanner'错误 TS2304:找不到名称“QRScanner”
【发布时间】:2022-02-17 14:10:07
【问题描述】:

我参考了https://www.npmjs.com/package/cordova-plugin-qrscanner 并尝试在我的移动应用中创建二维码扫描功能。

所以对于第一步,我在我的 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);

但是,我在尝试构建时遇到错误。

TS2304:找不到名称“QRScanner”

以下是我的版本:

  • Angular CLI:10.2.3
  • 节点:10.16.3
  • 操作系统:linux x64
  • 角度:10.2.5
  • npm 版本:6.9.0

我在 package.json 中的 cordova-plugin-qrscanner 版本是:

"@types/cordova-plugin-qrscanner": "^1.0.31",
"cordova-plugin-qrscanner": "^3.0.1",

【问题讨论】:

    标签: node.js angular cordova npm plugins


    【解决方案1】:

    早安,

    我找到了解决方案,以下是我的一些理解。 此代码适用于旧版本的 Angular。 我使用 angular 10,因此,需要先定义 QRScanner 对象。 这是:

    declare var QRScanner: any;

    或使用( < any > window).QRScanner 获取QRScanner 插件的访问权限。

    【讨论】:

      猜你喜欢
      • 2016-12-18
      • 2019-05-06
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      相关资源
      最近更新 更多