繁体   English   中英

ionic 'DocumentScanner' 指的是一个值,但在这里被用作一个类型

[英]ionic 'DocumentScanner' refers to a value, but is being used as a type here

我有以下代码:

import {Component} from '@angular/core';
import {DocumentScanner, DocumentScannerOptions, DocumentScannerSourceType} from '@ionic-native/document-scanner';

@Component({
    selector: 'app-tab2',
    templateUrl: 'tab2.page.html',
    styleUrls: ['tab2.page.scss']
})
export class Tab2Page {

    constructor(private documentScanner: DocumentScanner) {
    }

    scan() {
        const opts: DocumentScannerOptions = {
            sourceType: DocumentScannerSourceType.CAMERA,
            fileName: 'ticketScan.png',
            quality: 100,
            returnBase64: true
        };
        this.documentScanner.scanDoc(opts)
            .then((res: string) => console.log(res))
            .catch((error: any) => console.error(error));
    }
}

当我运行它时,我收到以下错误:

11:42 'DocumentScanner' refers to a value, but is being used as a type here.

谁能告诉我为什么会这样?

您需要在 app.module.ts 文件中导入 DocumentScanner

import { DocumentScanner } from '@ionic-native/document-scanner/ngx';

并将其添加到提供程序数组

providers: [
.....
   DocumentScanner ,
.....
]

同样在您的 page.ts 文件中,添加 /ngx/; 在文档扫描仪导入路径之后

import { DocumentScanner } from '@ionic-native/document-scanner/ngx/';

希望能帮助到你。

如此所述,如果项目中的任何文件缺少/ngx导入,即使在/ngx存在的文件中也可能导致问题。

因此,您应该检查每个文件是否缺少/ngx导入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM