gpt4 book ai didi

javascript - 错误 : StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]

转载 作者:行者123 更新时间:2023-12-04 01:42:07 31 4
gpt4 key购买 nike

我在我的 Ionic 4 应用程序中使用插件 '@ionic-native/bluetooth-serial/ngx' 与热敏打印机进行通信。如果我使用 android 7.1.1 为 android 设备编译源代码,它会显示此错误:

E/Capacitor/Plugin/Console: ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]: StaticInjectorError(Platform: core)[HomePage -> BluetoothSerial]: NullInjectorError: No provider for BluetoothSerial! Error: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]: StaticInjectorError(Platform: core)[HomePage -> BluetoothSerial]: NullInjectorError: No provider for BluetoothSerial! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (http: //localhost/vendor.js:42939:19) at resolveToken (http: //localhost/vendor.js:43184:24) at tryResolveToken (http: //localhost/vendor.js:43128:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http: //localhost/vendor.js:43025:20) at resolveToken (http: //localhost/vendor.js:43184:24) at tryResolveToken (http: //localhost/vendor.js:43128:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http: //localhost/vendor.js:43025:20) at resolveNgModuleDep (http: //localhost/vendor.js:55261:29) at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (http: //localhost/vendor.js:55950:16) at resolveNgModuleDep (http: //localhost/vendor.js:55261:29)

我只是导入了它,并在构造函数中添加了参数。

home.ts代码:

import { Component } from '@angular/core';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

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

infoText:string = '';

constructor(private bluetoothSerial: BluetoothSerial) {}

listAllItems()
{
this.infoText = 'Hier werden alle Geräte aufgelistet!!!';
}

isConnected()
{
this.infoText = 'Hier wird angezeigt ob es verbunden ist!!!';
}
}

有谁知道错误的原因吗?感谢您的帮助。

最佳答案

除了 native 插件页面上的说明之外,还有一些常规说明,您每次向项目添加插件时都必须遵循这些说明。

它们列在这里:

这意味着您需要编辑 app.module.ts 以将模块导入到项目中。然后它可以被应用程序的其余部分使用。

// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

...

@NgModule({
...

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

关于javascript - 错误 : StaticInjectorError(AppModule)[HomePage -> BluetoothSerial],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56902037/

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