gpt4 book ai didi

angular - 没有 BarcodeScanner 的提供者

转载 作者:太空狗 更新时间:2023-10-29 17:42:38 26 4
gpt4 key购买 nike

代码如下:

    import { Component } from '@angular/core';    import { NavController, Platform } from 'ionic-angular';    import { TranslateService } from '@ngx-translate/core';    import { BarcodeScanner } from '@ionic-native/barcode-scanner';    @Component({        selector: 'page-home',        templateUrl: 'home.html'    })    export class HomePage {        constructor(public navCtrl: NavController, private translate: TranslateService, private barcodeScanner: BarcodeScanner) {        }        //Switch language        changelanguage() {            let browserLang = this.translate.currentLang;            this.translate.use(browserLang.match(/en/) ? 'zh' : 'en');        }        //Scan test        ScanCode() {            this.barcodeScanner.scan()                .then((result) => {                    console.log(result);                })                .catch((error) => {                    alert(error);                });        }    }

错误图片:

enter image description here

引用: https://ionicframework.com/docs/native/barcode-scanner/



出现了新问题:
根据Suraj的建议,提示“plugin_not_installed”

错误图片:
enter image description here
enter image description here开发环境: Visual Studio 2017

最佳答案

您需要在 app.module.ts

中将扫描器设置为提供者
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

@NgModule({
...

providers: [
...
BarcodeScanner
...
]
...
})
export class AppModule { }

引用:Add Plugins to Your App's Module here

更新:从你的 package.json 看来你已经安装了旧的 ionic-native - 2.4.1。删除它并执行:

npm install --save @ionic-native/core

关于angular - 没有 BarcodeScanner 的提供者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43134892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com