簡體   English   中英

錯誤 TS2304:找不到名稱“QRScanner”

[英]error TS2304: Cannot find name 'QRScanner'

我參考https://www.npmjs.com/package/cordova-plugin-qrscanner並嘗試在我的移動應用程序中創建 QR 掃描 function。

因此,對於第一步,我在我的 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
  • Angular: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",

再會,

我找到了解決方案,以下是我的一些理解。 此代碼適用於舊版本的 angular。我使用的是 angular 10,因此,需要先定義QRScanner object。 這是:

declare var QRScanner: any ;

或者使用( < any > window).QRScanner來訪問 QRScanner 插件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM