Error: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]
Error: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]
我在我的 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!!!';
}
}
有谁知道错误的原因吗?感谢您的帮助。
除了本机插件页面上的说明之外,还有一些常规说明,您每次向项目添加插件时都必须遵循这些说明。
它们列在这里:
这意味着您需要编辑 app.module.ts 以将模块导入到项目中。然后它可以被应用程序的其余部分使用。
// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';
...
@NgModule({
...
providers: [
...
BluetoothSerial
...
]
...
})
export class AppModule { }
我在我的 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!!!';
}
}
有谁知道错误的原因吗?感谢您的帮助。
除了本机插件页面上的说明之外,还有一些常规说明,您每次向项目添加插件时都必须遵循这些说明。
它们列在这里:
这意味着您需要编辑 app.module.ts 以将模块导入到项目中。然后它可以被应用程序的其余部分使用。
// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';
...
@NgModule({
...
providers: [
...
BluetoothSerial
...
]
...
})
export class AppModule { }